Skip to content

Commit

Permalink
using download path path from drive download
Browse files Browse the repository at this point in the history
  • Loading branch information
collinschwantes committed Aug 5, 2024
1 parent d98abe1 commit 33eccff
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ohcleandat
Type: Package
Title: One Health Data Cleaning and Quality Checking Package
Version: 0.3.1
Version: 0.3.2
Authors@R: c(
person("Collin", "Schwantes", email = "[email protected]", role = c("cre", "aut"), comment = c(ORCID = "0000-0003-4014-4896")),
person("Johana", "Teigen", email = "[email protected]", role = "aut", comment = c(ORCID = "0000-0002-6209-2321")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ohcleandat 0.3.2

* Fixing issue with `download_google_drive` where search pattern is over applied.

# ohcleandat 0.3.1

* Explicitly adding `set_diff` function which was previously a hidden dependency on the {ecohealthalliance/airtabler} package
Expand Down
25 changes: 9 additions & 16 deletions R/download_googledrive_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' download_googledrive_files(
#' key_path = here::here("./key.json"),
#' drive_path = "https://drive.google.com/drive/u/0/folders/asdjfnasiffas8ef7y7y89rf",
#' search_pattern = "*.xlsx",
#' search_pattern = ".*\\.xlsx",
#' out_path = here::here("data/project_data/")
#' )
#' }
Expand All @@ -38,7 +38,7 @@ download_googledrive_files <-
# recursive search of drive folder for a given file type
files <- googledrive::drive_ls(
path = googledrive::as_id(drive_path),
recursive = T,
recursive = TRUE,
pattern = search_pattern,
type = googledrive::drive_mime_type(MIME_type)
)
Expand All @@ -47,27 +47,20 @@ download_googledrive_files <-
files_w_ext <- files |>
dplyr::mutate(
extension = purrr::map_chr(drive_resource, `[[`, "fileExtension"),
path = paste0(id, ".", extension)
path = paste0(id, ".", extension),
local_path = paste({{out_path}},path,sep = "/")
)

# download all files
purrr::map2(
downloaded_files <- purrr::map2_df(
.x = files_w_ext$id,
.y = files_w_ext$path,
~ googledrive::drive_download(.x, path = paste0(out_path, .y), overwrite = TRUE)
.y = files_w_ext$local_path,
~ googledrive::drive_download(.x, .y, overwrite = TRUE)
)

# return list of downloaded files for tracking
file_list <-
list.files(path = out_path,
pattern = search_pattern,
full.names = T)
# return local file paths

# return list of downloaded files for tracking
file_list <-
list.files(path = out_path,
pattern = search_pattern,
full.names = T)
file_list <- downloaded_files$local_path

return(file_list)
}
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ utils::globalVariables(
"extension",
"log_response_id",
"n",
"path", # used in download_googledrive_files in mutate
"rowid",
"entry_field",
"entry_field_dupe"
Expand Down
2 changes: 1 addition & 1 deletion man/download_googledrive_files.Rd

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

0 comments on commit 33eccff

Please sign in to comment.