Skip to content

Commit

Permalink
mv 'has_extension' -> 'has_file_ext' #38
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Oct 11, 2024
1 parent 6602d84 commit cd0381f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions R/export_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export_gtfs <- function(gtfs,
# input checks that depend on more than one argument

if (fs::file_exists(path) & !overwrite) error_cannot_overwrite()
if (!as_dir & !has_extension(path, "zip")) error_ext_must_be_zip()
if (as_dir & has_extension(path, "zip")) error_path_must_be_dir()
if (!as_dir & !has_file_ext(path, "zip")) error_ext_must_be_zip()
if (as_dir & has_file_ext(path, "zip")) error_path_must_be_dir()

extra_files <- setdiff(files, names(gtfsio::gtfs_reference))
if (standard_only & !is.null(files) & !identical(extra_files, character(0))) {
Expand Down Expand Up @@ -132,7 +132,7 @@ export_gtfs <- function(gtfs,

dt <- gtfs[[file]]

if (has_extension(filename, "geojson")) {
if (has_file_ext(filename, "geojson")) {
jsonlite::write_json(dt, filepath, pretty = FALSE, auto_unbox = TRUE, digits = 8)
} else {

Expand Down
4 changes: 2 additions & 2 deletions R/import_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ import_gtfs <- function(path,
)
if (inherits(filenames_in_gtfs, "error")) error_path_must_be_zip()

non_standard_file_ext <- filenames_in_gtfs[!(has_extension(filenames_in_gtfs, "txt") | has_extension(filenames_in_gtfs, "geojson"))]
non_standard_file_ext <- filenames_in_gtfs[!(has_file_ext(filenames_in_gtfs, "txt") | has_file_ext(filenames_in_gtfs, "geojson"))]

if (!identical(non_standard_file_ext, character(0))) {
warning(
Expand Down Expand Up @@ -241,7 +241,7 @@ read_files <- function(file,
stopifnot(length(file) == 1L)

filename <- file
file_type <- ifelse(has_extension(file, "txt"), "txt", "geojson")
file_type <- ifelse(has_file_ext(file, "txt"), "txt", "geojson")
file <- remove_file_ext(file)

if (!quiet) message("Reading ", file)
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ append_file_ext = function(file) {
# behaviour defined in test_import_gtfs.R#292
file_ext <- "txt"
}
if (!has_extension(.f, file_ext)) {
if (!has_file_ext(.f, file_ext)) {
.f <- fs::path_ext_set(.f, file_ext)
}
return(.f)
Expand All @@ -26,6 +26,6 @@ append_file_ext = function(file) {
#' with specified extension, `FALSE` otherwise.
#'
#' @noRd
has_extension <- function(path, ext = "zip") {
has_file_ext <- function(path, ext = "zip") {
fs::path_ext(path) == ext
}

0 comments on commit cd0381f

Please sign in to comment.