Skip to content

Commit

Permalink
clean_data_path() gains a normalize argument
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Onkelinx <[email protected]>
  • Loading branch information
ThierryO committed Aug 29, 2018
1 parent b427175 commit b748146
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 6 additions & 5 deletions R/data_repository.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,19 @@ meta.Date <- function(x, optimize = TRUE) {
##' Clean the data path
##' Strips any file extension from the path and adds the ".tsv" and ".yml" file extensions
##' @param path the paths
##' @param normalize normalize the path? Defaults to TRUE
##' @return a named vector with "raw_file" and "meta_file", refering to the ".tsv" and ".yml" files
##' @noRd
clean_data_path <- function(path) {
clean_data_path <- function(path, normalize = TRUE) {
dir_name <- dirname(path)
not_root <- dir_name != "."
path <- gsub("\\..*$", "", basename(path))
if (any(not_root)) {
path[not_root] <- file.path(dir_name[not_root], path[not_root])
}
path <- normalizePath(unique(path), winslash = "/", mustWork = FALSE)
if (isTRUE(normalize)) {
path <- normalizePath(unique(path), winslash = "/", mustWork = FALSE)
}
c(raw_file = paste0(path, ".tsv"), meta_file = paste0(path, ".yml"))
}

Expand Down Expand Up @@ -425,12 +428,10 @@ recent_commit <- function(repo, path = NULL, data = FALSE) {
if (length(path) != 1)
stop("'path' must be a single value")
if (data) {
path <- clean_data_path(path)
message("path: ", path)
path <- clean_data_path(path, normalize = FALSE)
}
name <- basename(path)
path <- unique(dirname(path))
message("path: ", path)
if (path == ".") {
path <- ""
}
Expand Down
5 changes: 1 addition & 4 deletions tests/data_repository.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,10 @@ stopifnot(inherits(com, "data.frame"))
stopifnot(all.equal(colnames(com), c("commit", "author", "when")))
stopifnot(all.equal(com$commit, commit_2$sha))

bl <- odb_blobs(data_repo)
bl[grepl("test", bl$name) & bl$path == "", c(2:3, 5, 7)]
commit_2$sha
com <- recent_commit(data_repo, "test", data = TRUE)
stopifnot(all.equal(com$commit, commit_2$sha))
stopifnot(inherits(com, "data.frame"))
stopifnot(all.equal(colnames(com), c("commit", "author", "when")))
stopifnot(all.equal(com$commit, commit_2$sha))

com <- recent_commit(data_repo, "junk/test", data = TRUE)
stopifnot(all.equal(com$commit, commit_3$sha))
Expand Down

0 comments on commit b748146

Please sign in to comment.