Skip to content

Commit

Permalink
using tools::R_user_dir to store r5r jar file
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Dec 5, 2023
1 parent aa1a7ed commit 861b4b4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
7 changes: 7 additions & 0 deletions r-package/NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
5 changes: 3 additions & 2 deletions r-package/R/download_r5.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion r-package/R/r5r_sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion r-package/R/setup_r5.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions r-package/tests/tests_rafa/test_rafa.R
Original file line number Diff line number Diff line change
Expand Up @@ -919,3 +919,4 @@ ggplot(data=df, aes(x=cost, y=time, label = modes)) +
theme_classic()



4 changes: 4 additions & 0 deletions r-package/tests/testthat/test-write_fare_structure.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 8 additions & 0 deletions r-package/vignettes/r5r.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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).


6 changes: 6 additions & 0 deletions r-package/vignettes/travel_time_matrix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 861b4b4

Please sign in to comment.