Skip to content

Commit

Permalink
Merge pull request #36 from hsvab/dro/read_od_nice_offline
Browse files Browse the repository at this point in the history
Undo force_download
  • Loading branch information
hsvab authored Nov 19, 2023
2 parents 4fd5e0f + 881b651 commit 1544f89
Show file tree
Hide file tree
Showing 22 changed files with 190 additions and 123 deletions.
Binary file modified .aspell/odbr.rds
Binary file not shown.
25 changes: 10 additions & 15 deletions R/download_piggyback.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#' Download file from odbr using piggyback
#'
#' @param filename_to_download String. The name of the file to be downloaded.
#' @param force_download Logical. If `FALSE` (default) the function will read
#' cached data downloaded previously in the same session. If `TRUE`, the
#' function will download the data and overwrite cached data.
#'
#' @return A string with the path to the file saved in a tempdir
#'
#' @keywords internal
download_piggyback <- function(filename_to_download,
force_download = FALSE) {
download_piggyback <- function(filename_to_download) {
# Defining our temporary directory
temp_dest_dir <- tempdir(check = TRUE)

Expand All @@ -19,17 +15,16 @@ download_piggyback <- function(filename_to_download,
# Creating path + filename and saving to "temporary_filename"
temp_full_file_path <- paste0(temp_dest_dir, "/", filename_to_download)

if (!file.exists(temp_full_file_path) || force_download) {
# downloading the file from a release of the odbr repo - release specified in the parameter
try(
silent = TRUE,
piggyback::pb_download(
file = filename_to_download,
repo = "hsvab/odbr",
dest = temp_dest_dir
)
# downloading the file from a release of the odbr repo - release specified in
# the parameter
try(
silent = TRUE,
piggyback::pb_download(
file = filename_to_download,
repo = "hsvab/odbr",
dest = temp_dest_dir
)
}
)

# Halt function if download failed
if (!file.exists(temp_full_file_path)) {
Expand Down
6 changes: 2 additions & 4 deletions R/read_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#' @template harmonize
#' @param geometry Character. The type of spatial data to be opened. Options
#' include `c("zone","district", "municipality")`.
#' @template force_download
#'
#' @return An `"sf" "data.frame"` object
#' @export
Expand Down Expand Up @@ -50,8 +49,7 @@
read_map <- function(city = "S\u00E3o Paulo",
year = 2017,
harmonize = FALSE,
geometry = "zone",
force_download = FALSE) {
geometry = "zone") {
# Clean the name of the city before comparing to the metadata
city_clean <- clean_string(city)

Expand Down Expand Up @@ -80,7 +78,7 @@ read_map <- function(city = "S\u00E3o Paulo",

# Calling the "download_piggyback" function with "filename_to_download" as
# parameter and saving the function return in "temporary_filename"
temporary_filename <- download_piggyback(filename_to_download, force_download)
temporary_filename <- download_piggyback(filename_to_download)

# check if download worked
if (is.null(temporary_filename)) {
Expand Down
6 changes: 2 additions & 4 deletions R/read_od.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @template city
#' @template year
#' @template harmonize
#' @template force_download
#'
#' @return A `"data.frame"` object.
#' @export
Expand All @@ -28,8 +27,7 @@
#'
read_od <- function(city = "S\u00E3o Paulo",
year = 2017,
harmonize = FALSE,
force_download = FALSE) {
harmonize = FALSE) {
# Clean the name of the city before comparing to the metadata
city_clean <- clean_string(city)

Expand All @@ -49,7 +47,7 @@ read_od <- function(city = "S\u00E3o Paulo",

# Calling the "download_piggyback" function with "filename_to_download" as
# parameter and saving the return in "temporary_filename"
temporary_filename <- download_piggyback(filename_to_download, force_download)
temporary_filename <- download_piggyback(filename_to_download)

# check if download worked
if (is.null(temporary_filename)) {
Expand Down
7 changes: 3 additions & 4 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1544f89

Please sign in to comment.