From 09f9439bba2e986f7e7bac2a0daac1548517b3c9 Mon Sep 17 00:00:00 2001 From: mpadge Date: Thu, 29 Aug 2024 09:55:40 +0200 Subject: [PATCH] use fs in all R code for #119 --- DESCRIPTION | 3 ++- R/extract-gtfs.R | 6 +++--- R/go_home_work.R | 4 ++-- R/transfers.R | 4 ++-- R/utils.R | 8 ++++---- codemeta.json | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7e385906..c8b75469 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gtfsrouter Title: Routing with 'GTFS' (General Transit Feed Specification) Data -Version: 0.1.2.015 +Version: 0.1.2.016 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Marcin", "Stepniak", , "marcinstepniak@ucm.es", role = "aut", @@ -18,6 +18,7 @@ Depends: Imports: cli, data.table, + fs, geodist, methods, Rcpp (>= 0.12.6) diff --git a/R/extract-gtfs.R b/R/extract-gtfs.R index 9716a71c..1a5fa296 100644 --- a/R/extract-gtfs.R +++ b/R/extract-gtfs.R @@ -89,7 +89,7 @@ unzip_gtfs <- function (filename, quiet = FALSE) { ) } - flist <- utils::unzip (filename, exdir = tempdir ()) + flist <- utils::unzip (filename, exdir = fs::path_temp ()) if (!quiet) { message ("\r", cli::col_green ( @@ -106,7 +106,7 @@ check_extract_pars <- function (filename, stn_suffixes) { if (is.null (filename)) { stop ("filename must be given") } - if (!file.exists (filename)) { + if (!fs::file_exists (filename)) { stop ("filename ", filename, " does not exist") } if (!(is.null (stn_suffixes) || is.character (stn_suffixes))) { @@ -191,7 +191,7 @@ extract_objs_into_env <- function (flist, quiet = FALSE) { value = fout, envir = e ) - chk <- file.remove (flist [f]) # nolint + chk <- fs::file_delete (flist [f]) # nolint } if (!quiet) { diff --git a/R/go_home_work.R b/R/go_home_work.R index 7e624475..d49920f2 100644 --- a/R/go_home_work.R +++ b/R/go_home_work.R @@ -104,7 +104,7 @@ go_home_work <- function (home = TRUE, wait, start_time) { vars <- get_envvars () fname <- get_rds_name (vars$file) - if (!file.exists (fname)) { + if (!fs::file_exists (fname)) { stop ( "This function requires the GTFS data to be pre-processed ", "with 'process_gtfs_local'." @@ -145,7 +145,7 @@ get_envvars <- function () { } f <- (Sys.getenv ("gtfs_data")) - if (!file.exists (f)) { + if (!fs::file_exists (f)) { stop ( "File ", f, " specified by environmental variable ", "'gtfs_data' does not exist" diff --git a/R/transfers.R b/R/transfers.R index 80d7f2e8..8b736fa0 100644 --- a/R/transfers.R +++ b/R/transfers.R @@ -130,9 +130,9 @@ dl_net <- function (gtfs) { stops <- gtfs$stops [, c ("stop_lon", "stop_lat")] requireNamespace ("digest") hash <- digest::digest (stops) - net_name <- file.path (tempdir (), paste0 ("net", hash, ".Rds")) + net_name <- fs::path (fs::path_temp (), paste0 ("net", hash, ".Rds")) - if (!file.exists (net_name)) { + if (!fs::file_exists (net_name)) { requireNamespace ("dodgr") net <- dodgr::dodgr_streetnet_sc (pts = stops) saveRDS (net, file = net_name) diff --git a/R/utils.R b/R/utils.R index 1d353f42..758db566 100644 --- a/R/utils.R +++ b/R/utils.R @@ -21,7 +21,7 @@ berlin_gtfs_to_zip <- function () { si <- strsplit (i, ".txt") [[1]] res <- tryCatch ( data.table::fwrite (f [[si]], - file.path (tempdir (), i), + fs::path (fs::path_temp (), i), quote = TRUE ), error = function (e) e @@ -33,10 +33,10 @@ berlin_gtfs_to_zip <- function () { stop ("Unable to write files to tempdir()") } # nocov - flist <- file.path (tempdir (), flist) - zipname <- file.path (tempdir (), "vbb.zip") + flist <- fs::path (fs::path_temp (), flist) + zipname <- fs::path (fs::path_temp (), "vbb.zip") utils::zip (zipname, files = flist, flags = "-q") - chk <- file.remove (flist) + chk <- fs::file_delete (flist) return (zipname) } diff --git a/codemeta.json b/codemeta.json index 9c48e8f6..531d06c6 100644 --- a/codemeta.json +++ b/codemeta.json @@ -7,7 +7,7 @@ "codeRepository": "https://github.com/UrbanAnalyst/gtfsrouter", "issueTracker": "https://github.com/UrbanAnalyst/gtfsrouter/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.2.015", + "version": "0.1.2.016", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",