From c7cbd5bd6922da71f223fb5796517409e29bbb69 Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Wed, 3 Apr 2024 20:26:57 -0300 Subject: [PATCH 01/10] update example r5r_cache --- r-package/R/r5r_cache.R | 7 +++++-- r-package/man/r5r_cache.Rd | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/r-package/R/r5r_cache.R b/r-package/R/r5r_cache.R index 9d500a7a..2e1f5a8e 100644 --- a/r-package/R/r5r_cache.R +++ b/r-package/R/r5r_cache.R @@ -12,11 +12,14 @@ #' @export #' @family Cache data #' @examplesIf identical(tolower(Sys.getenv("NOT_CRAN")), "true") +#' # download r5 JAR +#' r5r::download_r5() +#' #' # list all files cached #' r5r_cache(list_files = TRUE) #' -#' # delete particular file -#' r5r_cache(delete_file = '2010_deaths') +#' # delete r5 JAR +#' r5r_cache(delete_file = 'r5-v7.0') #' r5r_cache <- function(list_files = TRUE, delete_file = NULL){ diff --git a/r-package/man/r5r_cache.Rd b/r-package/man/r5r_cache.Rd index 9f81f558..3a4bc8d0 100644 --- a/r-package/man/r5r_cache.Rd +++ b/r-package/man/r5r_cache.Rd @@ -24,11 +24,14 @@ Manage cached files from the r5r package } \examples{ \dontshow{if (identical(tolower(Sys.getenv("NOT_CRAN")), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +# download r5 JAR +r5r::download_r5() + # list all files cached r5r_cache(list_files = TRUE) -# delete particular file -r5r_cache(delete_file = '2010_deaths') +# delete r5 JAR +r5r_cache(delete_file = 'r5-v7.0') \dontshow{\}) # examplesIf} } \concept{Cache data} From a550daf431e004c08b6ac57b55812f1903a719a5 Mon Sep 17 00:00:00 2001 From: Daniel Herszenhut Date: Thu, 4 Apr 2024 16:18:30 -0300 Subject: [PATCH 02/10] added error to setup_r5() when given dir cannot have content written to --- r-package/DESCRIPTION | 2 ++ r-package/R/setup_r5.R | 26 ++++++++++++++++++++++++ r-package/tests/testthat/test-setup_r5.R | 16 +++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/r-package/DESCRIPTION b/r-package/DESCRIPTION index bf0c2c91..db9a6911 100644 --- a/r-package/DESCRIPTION +++ b/r-package/DESCRIPTION @@ -40,10 +40,12 @@ Depends: R (>= 3.6) Imports: checkmate, + cli, concaveman, data.table, jsonlite, rJava (>= 0.9-10), + rlang, sf (>= 1.0-12), sfheaders, utils, diff --git a/r-package/R/setup_r5.R b/r-package/R/setup_r5.R index 11edf3d8..eeee9936 100644 --- a/r-package/R/setup_r5.R +++ b/r-package/R/setup_r5.R @@ -144,6 +144,10 @@ setup_r5 <- function(data_path, message("\nUsing cached network.dat from ", dat_file) } else { + # check if the user has permission to write to the data directory. if not, + # R5 won't be able to create the required files and will fail with a + # not-that-enlightening error + error_if_no_write_permission(data_path) # stop r5 in case it is already running suppressMessages( r5r::stop_r5() ) @@ -178,3 +182,25 @@ setup_r5 <- function(data_path, return(r5r_core) } + +error_if_no_write_permission <- function(data_path) { + write_permission <- file.access(data_path, mode = 2) + + normalized_path <- normalizePath(data_path) + + if (write_permission == -1) { + cli::cli_abort( + c( + "Permission to write to {.path {normalized_path}} denied.", + i = paste0( + "{.pkg r5r} needs write privilege to create the network files. ", + "Please make sure you have this privilege in the provided directory." + ) + ), + class = "dir_permission_denied", + call = rlang::caller_env() + ) + } + + return(invisible(TRUE)) +} diff --git a/r-package/tests/testthat/test-setup_r5.R b/r-package/tests/testthat/test-setup_r5.R index e41681fc..6bc479b1 100644 --- a/r-package/tests/testthat/test-setup_r5.R +++ b/r-package/tests/testthat/test-setup_r5.R @@ -63,3 +63,19 @@ test_that("'overwrite' parameter works correctly", { ) }) + +test_that("throws error if write access to given dir is denied", { + invisible(file.copy(path, tempdir(), recursive = TRUE)) + + tmpdir <- file.path(tempdir(), "poa") + + data_files <- list.files(tmpdir, full.names = TRUE) + files_to_remove <- data_files[grepl("network|\\.pbf\\.mapdb", data_files)] + if (length(files_to_remove) > 0) invisible(file.remove(files_to_remove)) + + Sys.chmod(tmpdir, "555") + + expect_error(setup_r5(tmpdir), class = "dir_permission_denied") + + Sys.chmod(tmpdir, "755") +}) From 63312bd283803935ceeba48c1f190738cf4bdbb1 Mon Sep 17 00:00:00 2001 From: Daniel Herszenhut Date: Thu, 4 Apr 2024 16:44:49 -0300 Subject: [PATCH 03/10] using time_window = 1 in fare_structure vignette to speed things up --- r-package/vignettes/fare_structure.Rmd | 58 ++++++++++++++------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/r-package/vignettes/fare_structure.Rmd b/r-package/vignettes/fare_structure.Rmd index db756ae5..8eecb6f2 100644 --- a/r-package/vignettes/fare_structure.Rmd +++ b/r-package/vignettes/fare_structure.Rmd @@ -342,17 +342,21 @@ points <- read.csv(system.file("extdata/poa/poa_hexgrid.csv", package = "r5r")) # calculate travel times function calculate_travel_times <- function(fare) { - - ttm_df <- travel_time_matrix(r5r_core, - origins = points, - destinations = points, - departure_datetime = as.POSIXct("13-05-2019 14:00:00", - format = "%d-%m-%Y %H:%M:%S"), - mode = c("WALK", "TRANSIT"), - fare_structure = fare_structure, - max_fare = fare, - max_trip_duration = 40, - max_walk_time = 20) + ttm_df <- travel_time_matrix( + r5r_core, + origins = points, + destinations = points, + mode = c("WALK", "TRANSIT"), + departure_datetime = as.POSIXct( + "13-05-2019 14:00:00", + format = "%d-%m-%Y %H:%M:%S" + ), + time_window = 1, + fare_structure = fare_structure, + max_fare = fare, + max_trip_duration = 40, + max_walk_time = 20 + ) return(ttm_df) } @@ -426,24 +430,26 @@ and compare the results the accessibility unconstrained by monetary costs: ```{r} # calculate accessibility function calculate_accessibility <- function(fare, fare_string) { - - access_df <- accessibility(r5r_core, - origins = points, - destinations = points, - departure_datetime = as.POSIXct("13-05-2019 14:00:00", - format = "%d-%m-%Y %H:%M:%S"), - opportunities_colname = "healthcare", - mode = c("WALK", "TRANSIT"), - cutoffs = 40, - fare_structure = fare_structure, - max_fare = fare, - max_trip_duration = 40, - max_walk_time = 20, - progress = FALSE) + access_df <- accessibility( + r5r_core, + origins = points, + destinations = points, + mode = c("WALK", "TRANSIT"), + departure_datetime = as.POSIXct( + "13-05-2019 14:00:00", + format = "%d-%m-%Y %H:%M:%S" + ), + time_window = 1, + opportunities_colname = "healthcare", + cutoffs = 40, + fare_structure = fare_structure, + max_fare = fare, + max_trip_duration = 40, + max_walk_time = 20, + progress = FALSE) access_df$max_fare <- fare_string - return(access_df) } From b7aaa2f67b3c4f3b2485c01582749ac862f524bd Mon Sep 17 00:00:00 2001 From: Daniel Herszenhut Date: Thu, 4 Apr 2024 17:23:16 -0300 Subject: [PATCH 04/10] removed nocov comment that caused coverage action to fail --- r-package/R/onLoad.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r-package/R/onLoad.R b/r-package/R/onLoad.R index b52b3f24..e4624e94 100644 --- a/r-package/R/onLoad.R +++ b/r-package/R/onLoad.R @@ -10,7 +10,7 @@ } # package global variables -r5r_env <- new.env(parent = emptyenv()) # nocov start +r5r_env <- new.env(parent = emptyenv()) .onLoad <- function(lib, pkg) { From 16d8a70843bc7b8b23ff9131534ad8955eeca631 Mon Sep 17 00:00:00 2001 From: Daniel Herszenhut Date: Thu, 4 Apr 2024 17:50:33 -0300 Subject: [PATCH 05/10] skipping file permission-related tests in windows --- r-package/tests/testthat/test-setup_r5.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/r-package/tests/testthat/test-setup_r5.R b/r-package/tests/testthat/test-setup_r5.R index 6bc479b1..43b3c9cf 100644 --- a/r-package/tests/testthat/test-setup_r5.R +++ b/r-package/tests/testthat/test-setup_r5.R @@ -65,6 +65,10 @@ test_that("'overwrite' parameter works correctly", { }) test_that("throws error if write access to given dir is denied", { + # this test only works correctly with unix OSes. not sure how to change + # permissions from inside R in windows + skip_if_not(.Platform$OS.type == "unix") + invisible(file.copy(path, tempdir(), recursive = TRUE)) tmpdir <- file.path(tempdir(), "poa") From f133004752e9bcd4b674fece1924d18d08a35adc Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Fri, 5 Apr 2024 00:01:35 -0300 Subject: [PATCH 06/10] update DESCRIPTION --- r-package/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r-package/DESCRIPTION b/r-package/DESCRIPTION index bf0c2c91..9b22e9c8 100644 --- a/r-package/DESCRIPTION +++ b/r-package/DESCRIPTION @@ -32,7 +32,7 @@ Description: Rapid realistic routing on multimodal transport networks independent update process. Hence, users should confirm the R5 version implied by the Conveyal user manual (see ) corresponds with the R5 version - that r5r depends on. + that r5r depends on. This version of r5r depends on R5 v7.0. License: MIT + file LICENSE URL: https://github.com/ipeaGIT/r5r BugReports: https://github.com/ipeaGIT/r5r/issues From e5eaf50859b48da0de13bcdd582cb8e9e48ab8ff Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Fri, 5 Apr 2024 00:01:53 -0300 Subject: [PATCH 07/10] test-z_r5r_cache --- r-package/tests/{tests_rafa => testthat}/test-z_r5r_cache.R | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename r-package/tests/{tests_rafa => testthat}/test-z_r5r_cache.R (100%) diff --git a/r-package/tests/tests_rafa/test-z_r5r_cache.R b/r-package/tests/testthat/test-z_r5r_cache.R similarity index 100% rename from r-package/tests/tests_rafa/test-z_r5r_cache.R rename to r-package/tests/testthat/test-z_r5r_cache.R From 9d0b18db425f4788adca9a08f5f8e887fe74948b Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Fri, 5 Apr 2024 19:38:13 -0300 Subject: [PATCH 08/10] using find_snap JDK on cmd-check --- .github/workflows/R-CMD-check.yaml | 7 +++++-- r-package/tests/testthat/test-z_r5r_cache.R | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index cc54ace6..9216453a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -52,10 +52,13 @@ jobs: - uses: r-lib/actions/setup-pandoc@v2 - name: Java setup - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: + distribution: 'temurin' java-version: '21' - java-package: jdk + cache: 'gradle' + - run: ./gradlew build + - name: Query dependencies run: | diff --git a/r-package/tests/testthat/test-z_r5r_cache.R b/r-package/tests/testthat/test-z_r5r_cache.R index becf82fb..5a741695 100644 --- a/r-package/tests/testthat/test-z_r5r_cache.R +++ b/r-package/tests/testthat/test-z_r5r_cache.R @@ -3,7 +3,6 @@ context("r5r_cache") # skip tests because they take too much time skip_if(Sys.getenv("TEST_ONE") != "") testthat::skip_on_cran() -testthat::skip_if_not_installed("arrow") try(silent = TRUE, r5r::stop_r5()) From a2904da765602f27c2b5d3968478d708e098f03b Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Fri, 5 Apr 2024 19:55:33 -0300 Subject: [PATCH 09/10] reorder functions in pkgdown website --- r-package/pkgdown/_pkgdown.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/r-package/pkgdown/_pkgdown.yml b/r-package/pkgdown/_pkgdown.yml index cbf73f79..c38070de 100644 --- a/r-package/pkgdown/_pkgdown.yml +++ b/r-package/pkgdown/_pkgdown.yml @@ -14,8 +14,6 @@ reference: - download_r5 - setup_r5 - stop_r5 - - r5r_sitrep - - r5r_cache - title: "Accessibility" - contents: - accessibility @@ -23,18 +21,22 @@ reference: - contents: - travel_time_matrix - expanded_travel_time_matrix - - pareto_frontier - detailed_itineraries + - pareto_frontier - title: "Isochrone" - contents: - isochrone - - title: "Network" + - title: "Extract Network data" - contents: - street_network_to_sf - transit_network_to_sf - - find_snap - title: "Fare structure" - contents: - setup_fare_structure - read_fare_structure - write_fare_structure + - title: "Support functions" + - contents: + - find_snap + - r5r_sitrep + - r5r_cache From 1759b0e2ceabe3f4cdeb4d47cf5c13011c25d2d8 Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Fri, 5 Apr 2024 20:08:01 -0300 Subject: [PATCH 10/10] fix GA --- .github/workflows/R-CMD-check.yaml | 1 - r-package/pkgdown/_pkgdown.yml | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 9216453a..5c36311b 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -57,7 +57,6 @@ jobs: distribution: 'temurin' java-version: '21' cache: 'gradle' - - run: ./gradlew build - name: Query dependencies diff --git a/r-package/pkgdown/_pkgdown.yml b/r-package/pkgdown/_pkgdown.yml index c38070de..c337fe49 100644 --- a/r-package/pkgdown/_pkgdown.yml +++ b/r-package/pkgdown/_pkgdown.yml @@ -9,11 +9,9 @@ repo: source: https://github.com/ipeaGIT/r5r/tree/master/r-package/ reference: - - title: "Setup" + - title: "Setup network" - contents: - - download_r5 - setup_r5 - - stop_r5 - title: "Accessibility" - contents: - accessibility @@ -26,7 +24,7 @@ reference: - title: "Isochrone" - contents: - isochrone - - title: "Extract Network data" + - title: "Extract Network spatial data" - contents: - street_network_to_sf - transit_network_to_sf @@ -40,3 +38,6 @@ reference: - find_snap - r5r_sitrep - r5r_cache + - download_r5 + - stop_r5 +