-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from mpadge/fs
Use fs for file path manipulations; closes #38
- Loading branch information
Showing
4 changed files
with
60 additions
and
48 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,31 @@ | ||
remove_file_ext = function(file) { | ||
fs::path_ext_remove(file) | ||
} | ||
|
||
append_file_ext = function(file) { | ||
vapply(file, function(.f) { | ||
file_ext <- gtfsio::gtfs_reference[[remove_file_ext(.f)]][["file_ext"]] | ||
if (is.null(file_ext)) { | ||
# use default for argument-specified non-standard files, | ||
# behaviour defined in test_import_gtfs.R#292 | ||
file_ext <- "txt" | ||
} | ||
if (!has_file_ext(.f, file_ext)) { | ||
.f <- fs::path_ext_set(.f, file_ext) | ||
} | ||
return(.f) | ||
}, ".txt", USE.NAMES = FALSE) | ||
} | ||
|
||
#' Vectorized assertion of path extensions | ||
#' | ||
#' @param path Vector of file paths | ||
#' @param ext File extension to be asserted for each `path` | ||
#' | ||
#' @return Logical vector of same length as `path`, with `TRUE` for each element | ||
#' with specified extension, `FALSE` otherwise. | ||
#' | ||
#' @noRd | ||
has_file_ext <- function(path, ext = "zip") { | ||
fs::path_ext(path) == ext | ||
} |