Skip to content

Commit

Permalink
download JAR from github
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Feb 11, 2022
1 parent 6156070 commit 2e8b9ac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
17 changes: 8 additions & 9 deletions r-package/R/download_r5.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ download_r5 <- function(version = "6.4.0",

# download R5's jar -----------------------------------------------------

filename <- filename_from_metadata(version)
download_url <- file.path(
"https://www.ipea.gov.br/geobr/r5r/jar_repo",
filename
)
file_url <- fileurl_from_metadata(version)
filename <- basename(file_url)

destfile <- data.table::fifelse(
temp_dir,
Expand All @@ -66,7 +63,7 @@ download_r5 <- function(version = "6.4.0",
return(destfile)
}

if (isFALSE(check_connection(download_url))) {
if (isFALSE(check_connection(file_url))) {
# if (!quiet)
# message(
# "Problem connecting to the data server. ",
Expand All @@ -75,16 +72,18 @@ download_r5 <- function(version = "6.4.0",
return(invisible(NULL))
}

# create dir
jar_dir <- system.file("jar", package = "r5r")
if (!dir.exists(jar_dir)) dir.create(jar_dir)

# download JAR
if (!quiet) message("R5 will be saved to ", destfile)
utils::download.file(
url = download_url,
url = file_url,
destfile = destfile,
mode = "wb",
method = "curl",
extra = "--insecure",
# method = "curl",
# extra = "--insecure",
quiet = quiet
)

Expand Down
7 changes: 5 additions & 2 deletions r-package/R/setup_r5.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ setup_r5 <- function(data_path,
# check if the most recent JAR release is stored already. If it's not
# download it

filename <- filename_from_metadata(version)
fileurl <- fileurl_from_metadata(version)
filename <- basename(fileurl)

jar_file <- data.table::fifelse(
temp_dir,
Expand All @@ -105,8 +106,10 @@ setup_r5 <- function(data_path,
existing_files[grepl("r5r", existing_files)]
)

# r5r jar
rJava::.jaddClassPath(path = r5r_jar)
rJava::.jaddClassPath(path = jar_file)
# R5 jar
rJava::.jaddClassPath(path = jar_file) ##### 66666 ler do temp ou disco local

# check if data_path already has a network.dat file
dat_file <- file.path(data_path, "network.dat")
Expand Down
13 changes: 5 additions & 8 deletions r-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ set_suboptimal_minutes <- function(r5r_core, suboptimal_minutes) {



#' Get most recent JAR filename from metadata
#' Get most recent JAR file url from metadata
#'
#' Returns the most recent JAR filename from metadata, depending on the version.
#' Returns the most recent JAR file url from metadata, depending on the version.
#'
#' @param version A string, the version of R5's to get the filename of.
#'
#' @return The filename as a string.
#' @return The a url a string.
#'
#' @family support functions
filename_from_metadata <- function(version) {
fileurl_from_metadata <- function(version) {

checkmate::assert_string(version)

Expand All @@ -458,10 +458,7 @@ filename_from_metadata <- function(version) {
metadata <- metadata[version == get("version", envir = env)]
metadata <- metadata[release_date == max(release_date)]
url <- metadata$download_path

filename <- basename(url)

return(filename)
return(url)

}

Expand Down
1 change: 1 addition & 0 deletions r-package/inst/extdata/metadata_r5r.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ version;release_date;download_path
6.4.0;20210715;https://www.ipea.gov.br/geobr/r5r/jar_repo/r5-v6.4-all_20210715.jar
6.4.0;20210820;https://www.ipea.gov.br/geobr/r5r/jar_repo/r5-v6.4-all_20210820.jar
6.4.0;20211021;https://www.ipea.gov.br/geobr/r5r/jar_repo/r5-v6.4-all_20211021.jar
6.4.0;20220211;https://github.com/ipeaGIT/r5/releases/download/v6.4/r5-v6.4-all.jar

0 comments on commit 2e8b9ac

Please sign in to comment.