Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_vc(), write_vc(), rm_data(): default root #6

Merged
merged 14 commits into from
Feb 1, 2019
Merged
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Authors@R: c(
"Thierry", "Onkelinx", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-8804-4216")),
person(
"Floris", "Vanderhaeghe", role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0002-6378-6229")),
person(
"Research Institute for Nature and Forest",
role = c("cph", "fnd"), email = "[email protected]"))
Expand Down
15 changes: 14 additions & 1 deletion R/read_vc.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@
#' @importFrom methods setGeneric
setGeneric(
name = "read_vc",
def = function(file, root){
def = function(file, root = "."){
standardGeneric("read_vc") # nocov
}
)

#' @rdname read_vc
#' @importFrom methods setMethod
setMethod(
f = "read_vc",
signature = signature(root = "ANY"),
definition = function(file, root){
if (missing(root)) {
return(read_vc(file = file, root = "."))
}
stop("a 'root' of class ", class(root), " is not supported")
}
)

#' @rdname read_vc
#' @importFrom methods setMethod
#' @importFrom assertthat assert_that is.string
Expand Down
1 change: 1 addition & 0 deletions R/recent_commit.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Most recent file change
#' Retrieve the most recent commit in which a file or data object existed.
#' @inheritParams write_vc
#' @param root The root of a project. Can be a file path or a `git-repository`
#' @param data refers file to a file (FALSE) or a data object (TRUE). Defaults
#' to FALSE
#' @return a `data.frame` with `commit`, `author` and `when` for the most recent
Expand Down
22 changes: 21 additions & 1 deletion R/rm_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@
setGeneric(
name = "rm_data",
def = function(
root, path = NULL, type = c("tsv", "yml", "both"), recursive = TRUE, ...
root = ".", path = NULL, type = c("tsv", "yml", "both"), recursive = TRUE,
...
){
standardGeneric("rm_data") # nocov
}
)

#' @rdname rm_data
#' @importFrom methods setMethod
setMethod(
f = "rm_data",
signature = signature(root = "ANY"),
definition = function(
root, path = NULL, type = c("tsv", "yml", "both"), recursive = TRUE, ...
){
if (missing(root)) {
return(
rm_data(
root = ".", path = path, type = type, recursive = recursive, ...
)
)
}
stop("a 'root' of class ", class(root), " is not supported")
}
)

#' @rdname rm_data
#' @importFrom methods setMethod
#' @importFrom assertthat assert_that is.flag
Expand Down
12 changes: 9 additions & 3 deletions R/write_vc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#' @param x the `data.frame
#' @param file the name of the file without file extension. Can include a
#' relative path. It is relative to the `root`.
#' @param root The root of a project. Can be a file path or a `git-repository`
#' @param root The root of a project. Can be a file path or a `git-repository`.
#' Defaults to the current working directory (".").
#' @param sorting a vector of column names defining which columns to use for
#' sorting \code{x} and in what order to use them. Only required when writing
#' new metadata.
Expand All @@ -24,7 +25,7 @@
setGeneric(
name = "write_vc",
def = function(
x, file, root, sorting, override = FALSE, optimize = TRUE, ...
x, file, root = ".", sorting, override = FALSE, optimize = TRUE, ...
){
standardGeneric("write_vc") # nocov
}
Expand All @@ -39,7 +40,12 @@ setMethod(
x, file, root, sorting, override = FALSE, optimize = TRUE, ...
){
if (missing(root)) {
stop("'root' is missing")
return(
write_vc(
x = x, file = file, root = ".", sorting = sorting,
override = override, optimize = optimize, ...
)
)
}
stop("a 'root' of class ", class(root), " is not supported")
}
Expand Down
17 changes: 13 additions & 4 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"version": "3.5.1",
"version": "3.5.2",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 3.5.1 (2018-07-02)",
"runtimePlatform": "R version 3.5.2 (2018-12-20)",
"author": [
{
"@type": "Person",
Expand Down Expand Up @@ -139,7 +139,7 @@
}
],
"readme": "https://github.com/inbo/git2rdata/blob/master/README.md",
"fileSize": "36.79KB",
"fileSize": "69.924KB",
"contIntegration": [
"https://travis-ci.org/inbo/git2rdata",
"https://ci.appveyor.com/project/ThierryO/git2rdata/branch/master",
Expand All @@ -154,5 +154,14 @@
"version-control",
"reproducible-research"
],
"relatedLink": "https://doi.org/10.5281/zenodo.1485309"
"relatedLink": "https://doi.org/10.5281/zenodo.1485309",
"contributor": [
{
"@type": "Person",
"givenName": "Floris",
"familyName": "Vanderhaeghe",
"email": "[email protected]",
"@id": "https://orcid.org/0000-0002-6378-6229"
}
]
}
1 change: 1 addition & 0 deletions man/git2rdata-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions man/read_vc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions man/rm_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions man/write_vc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion tests/testthat/test_a_basics.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
context("write_vc() and read_vc() on a file system")
expect_error(write_vc(), "'root' is missing")
expect_error(write_vc(root = 1), "a 'root' of class numeric is not supported")
expect_error(read_vc(root = 1), "a 'root' of class numeric is not supported")
output <- write_vc(x = test_data,
file = "test.txt",
sorting = "test_Date")
expect_true(all(file.exists(git2rdata:::clean_data_path(".", "test"))))
expect_equal(
stored <- read_vc(file = "test.xls"),
sorted_test_data,
check.attributes = FALSE
)
if (file.exists("test.tsv")) file.remove("test.tsv")
if (file.exists("test.yml")) file.remove("test.yml")
root <- tempfile(pattern = "git2rdata-basic")
dir.create(root)
expect_false(any(file.exists(git2rdata:::clean_data_path(root, "test"))))
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test_b_rm_data.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
context("rm_data")

expect_error(rm_data(root = 1), "a 'root' of class numeric is not supported")

root <- tempfile(pattern = "git2rdata-")
expect_error(rm_data(root), root)
dir.create(root)
Expand Down Expand Up @@ -37,3 +39,14 @@ expect_identical(
list.files(root, recursive = TRUE),
current[-grep("^.*/.*", current)]
)

write_vc(test_data, file = "test", sorting = "test_Date")
current <- list.files(".", recursive = TRUE)
expect_identical(
rm_data(type = "both", recursive = FALSE),
c("test.tsv", "test.yml")
)
expect_identical(
list.files(".", recursive = TRUE),
current[grep("^.*/.*", current)]
)