From 861b4b4082d6faa6d0bd5998cb608a12cacd2952 Mon Sep 17 00:00:00 2001 From: rafapereirabr Date: Tue, 5 Dec 2023 09:45:21 -0300 Subject: [PATCH] using tools::R_user_dir to store r5r jar file --- r-package/NEWS.md | 7 +++++++ r-package/R/download_r5.R | 5 +++-- r-package/R/r5r_sitrep.R | 2 +- r-package/R/setup_r5.R | 2 +- r-package/tests/tests_rafa/test_rafa.R | 1 + r-package/tests/testthat/test-write_fare_structure.R | 4 ++++ r-package/vignettes/r5r.Rmd | 8 ++++++++ r-package/vignettes/travel_time_matrix.Rmd | 6 ++++++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/r-package/NEWS.md b/r-package/NEWS.md index 578950ae..e3a06d6f 100644 --- a/r-package/NEWS.md +++ b/r-package/NEWS.md @@ -1,5 +1,12 @@ # r5r 1.1.0999 dev + +**Major changes** + +- r5r uses the latest V7 of R5. Closed [#350](https://github.com/ipeaGIT/r5r/issues/350) +- r5r uses JDK 21 or higher (Breaking changes). Closed [#350](https://github.com/ipeaGIT/r5r/issues/350) + + **Minor changes** - In the `accessibility()` function, the value of `max_trip_duration` is now capped by the max value passed to the `cutoffs` parameter. Closes [#342](https://github.com/ipeaGIT/r5r/issues/348). diff --git a/r-package/R/download_r5.R b/r-package/R/download_r5.R index 7292d943..ae1fa471 100644 --- a/r-package/R/download_r5.R +++ b/r-package/R/download_r5.R @@ -48,9 +48,10 @@ download_r5 <- function(version = "7.0.0", destfile <- data.table::fifelse( temp_dir, file.path(tempdir(), filename), - file.path(system.file("jar", package = "r5r"), filename) + file.path(tools::R_user_dir("r5r", which = "cache"), filename) ) + # check if the file exists, and returns its path if it does. otherwise, # download it from IPEA's server - if there's no internet connection "fail # gracefully" (i.e invisibly returns NULL and outputs a informative message)" @@ -70,7 +71,7 @@ download_r5 <- function(version = "7.0.0", } # create dir - jar_dir <- system.file("jar", package = "r5r") + jar_dir <- tools::R_user_dir("r5r", which = "cache") if (!dir.exists(jar_dir)) dir.create(jar_dir) # download JAR diff --git a/r-package/R/r5r_sitrep.R b/r-package/R/r5r_sitrep.R index 2b2c8d8c..e6a7aa74 100644 --- a/r-package/R/r5r_sitrep.R +++ b/r-package/R/r5r_sitrep.R @@ -19,7 +19,7 @@ r5r_sitrep <- function() { r5r_package_version <- utils::packageVersion("r5r") - jar_dir <- system.file("jar", package = "r5r") + jar_dir <- tools::R_user_dir("r5r", which = "cache") jar_dir_files <- list.files(jar_dir) jar_dir_files_full_names <- list.files(jar_dir, full.names = TRUE) diff --git a/r-package/R/setup_r5.R b/r-package/R/setup_r5.R index ca1ba5cf..261845fb 100644 --- a/r-package/R/setup_r5.R +++ b/r-package/R/setup_r5.R @@ -116,7 +116,7 @@ setup_r5 <- function(data_path, jar_file <- data.table::fifelse( temp_dir, file.path(tempdir(), filename), - file.path(system.file("jar", package = "r5r"), filename) + file.path(tools::R_user_dir("r5r", which = "cache"), filename) ) # If there isn't a JAR already, download it diff --git a/r-package/tests/tests_rafa/test_rafa.R b/r-package/tests/tests_rafa/test_rafa.R index 5a96931d..8d6646e3 100644 --- a/r-package/tests/tests_rafa/test_rafa.R +++ b/r-package/tests/tests_rafa/test_rafa.R @@ -919,3 +919,4 @@ ggplot(data=df, aes(x=cost, y=time, label = modes)) + theme_classic() + diff --git a/r-package/tests/testthat/test-write_fare_structure.R b/r-package/tests/testthat/test-write_fare_structure.R index 8c74d28c..78180a14 100644 --- a/r-package/tests/testthat/test-write_fare_structure.R +++ b/r-package/tests/testthat/test-write_fare_structure.R @@ -29,3 +29,7 @@ test_that("written structure is identical to original", { written_struc <- read_fare_structure(tmpfile) expect_identical(struc, written_struc) }) + +# clean cache +jar_dir <- tools::R_user_dir("r5r", which = "cache") +list.files(jar_dir, full.names = TRUE) |> file.remove() diff --git a/r-package/vignettes/r5r.Rmd b/r-package/vignettes/r5r.Rmd index 3f051566..63966f14 100644 --- a/r-package/vignettes/r5r.Rmd +++ b/r-package/vignettes/r5r.Rmd @@ -362,4 +362,12 @@ r5r::stop_r5(r5r_core) rJava::.jgc(R.gc = TRUE) ``` +```{r, eval = TRUE, include = FALSE, message = FALSE} +# clean cache (CRAN policy) +jar_dir <- tools::R_user_dir("r5r", which = "cache") +list.files(jar_dir, full.names = TRUE) |> file.remove() +``` + If you have any suggestions or want to report an error, please visit [the package GitHub page](https://github.com/ipeaGIT/r5r). + + diff --git a/r-package/vignettes/travel_time_matrix.Rmd b/r-package/vignettes/travel_time_matrix.Rmd index 4caa299c..2dfeeceb 100644 --- a/r-package/vignettes/travel_time_matrix.Rmd +++ b/r-package/vignettes/travel_time_matrix.Rmd @@ -164,6 +164,12 @@ r5r::stop_r5(r5r_core) rJava::.jgc(R.gc = TRUE) ``` +```{r, eval = TRUE, include = FALSE, message = FALSE} +# clean cache (CRAN policy) +jar_dir <- tools::R_user_dir("r5r", which = "cache") +list.files(jar_dir, full.names = TRUE) |> file.remove() +``` + If you have any suggestions or want to report an error, please visit [the package GitHub page](https://github.com/ipeaGIT/r5r). ## References