-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c65d254
commit 1c7a45e
Showing
15 changed files
with
191 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#' @title Add identifier to columns | ||
#' | ||
#' @description Add a prefixed identifier to the first column of the dataset. | ||
#' @inheritParams dataset | ||
#' @param prefix Defaults to \code{eg:} (example.com). | ||
#' @param ids Defaults to \code{NULL}. | ||
#' @return A dataset conforming the original sub-class of \code{x}. | ||
#' @examples | ||
#' | ||
#' # Example with a dataaset object: | ||
#' id_to_column(iris_dataset) | ||
#' | ||
#' # Example with a data.frame object: | ||
#' | ||
#' id_to_column(iris, prefix="eg:iris-o") | ||
#' @export | ||
id_to_column <- function(x, prefix = "eg:", ids = NULL) { | ||
|
||
is_dataset <- is.dataset(x) | ||
|
||
lastcol <- ncol(x) | ||
|
||
if (is.null(ids)) { | ||
ids <- gsub("[^[:alnum:]]", "-", row.names(x)) | ||
} else if (nrow(x)!=length(ids)) { | ||
stop("id_to_column(x, ..., ids) : ids must be of same lengths as nrow(x).") | ||
} | ||
|
||
if (is.null(prefix)) { prefix <- "" } | ||
|
||
rhs <- x | ||
x$rowid <- paste0(prefix, ids) | ||
lhs <- x[, "rowid", drop=FALSE] | ||
|
||
if (is_dataset) { | ||
|
||
DataBibentry <- dataset_bibentry(rhs) | ||
tmp <- dataset(cbind(lhs, rhs), | ||
author=DataBibentry$author, | ||
title = DataBibentry$title) | ||
|
||
if (nrow(tmp)>0) { | ||
row.names(tmp) <- 1:nrow(tmp) | ||
} else { | ||
row.names(tmp) <- NULL | ||
} | ||
|
||
attr(tmp, "DataBibentry") <- DataBibentry | ||
|
||
} else { | ||
tmp <- cbind(lhs, rhs) | ||
} | ||
tmp | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
|
||
test_that("dataset_to_triples works()", { | ||
expect_equal(class(dataset_to_triples(iris_dataset)), "data.frame") | ||
expect_equal(ncol(dataset_to_triples(iris_dataset)), 3) | ||
expect_equal(nrow(dataset_to_triples(head(iris_dataset, 3))), dim(head(iris_dataset, 3))[1]*dim(head(iris_dataset, 3))[2]) | ||
}) | ||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.