Skip to content

Commit

Permalink
use fs in all R code for #119
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Aug 29, 2024
1 parent 0399a41 commit 09f9439
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Marcin", "Stepniak", , "[email protected]", role = "aut",
Expand All @@ -18,6 +18,7 @@ Depends:
Imports:
cli,
data.table,
fs,
geodist,
methods,
Rcpp (>= 0.12.6)
Expand Down
6 changes: 3 additions & 3 deletions R/extract-gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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))) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions R/go_home_work.R
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions R/transfers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 09f9439

Please sign in to comment.