-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.R
31 lines (29 loc) · 881 Bytes
/
utils.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}