Skip to content

Commit

Permalink
Update download.R to allow year vectors for baci data (#250)
Browse files Browse the repository at this point in the history
* Update download.R to allow year vectors for baci data 

Ensures 'path' is the single url in 'param$url' for baci source in external_download.

* download: fixing str_replace error more generally

now this won't happen for baci, but also for other functions

---------

Co-authored-by: Igor Rigolon <[email protected]>
  • Loading branch information
OlivazShai and IgorRigolon authored Sep 6, 2024
1 parent 5f0a8ab commit 85204d2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,19 @@ external_download <- function(dataset = NULL, source = NULL, year = NULL,
# Some URLs are in the form www.data/$year$_$dataset$.csv, where expression
# surrounded by $ are placeholders. The code below subs them in for actual parameters

if (!is.null(param$year)) {
path <- path %>%
stringr::str_replace("\\$year\\$", as.character(param$year))
}
if (!is.null(param$state)) {
path <- path %>%
stringr::str_replace("\\$state\\$", param$state)
}
if (!is.null(param$file_name)) {
path <- path %>%
stringr::str_replace("\\$file_name\\$", param$file_name)
if (stringr::str_detect(path, "\\$year\\$|\\$state\\$|\\$file_name\\$")) {
if (!is.null(param$year)) {
path <- path %>%
stringr::str_replace("\\$year\\$", as.character(param$year))
}
if (!is.null(param$state)) {
path <- path %>%
stringr::str_replace("\\$state\\$", param$state)
}
if (!is.null(param$file_name)) {
path <- path %>%
stringr::str_replace("\\$file_name\\$", param$file_name)
}
}

# Below are the exceptions, for which manipulation is needed
Expand Down

0 comments on commit 85204d2

Please sign in to comment.