Skip to content

Commit

Permalink
Add option to checkout specific release to manage_local_EC_archive
Browse files Browse the repository at this point in the history
  • Loading branch information
rfiorella committed Aug 7, 2023
1 parent f8ec658 commit 0a89fa5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* This will be the last release that has the *_by_month functions! They have
deprecated for about a year, and will be removed before next release. Use
calibrate_carbon (mature) or calibrate_water (experimental).
* Adds an argument to manage_local_EC_archive that allows checking out
specific releases (e.g., RELEASE-2023) instead of release + provisional. To check
out all data, set to NULL.
* Exports get_Rstd, a helper function to return the heavy-to-light isotope
ratio of the relevant international standard.
* Allows use of the useFasttime argument in dependency neonUtilities::stackEddy,
Expand Down
38 changes: 21 additions & 17 deletions R/utility_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ manage_local_EC_archive <- function(file_dir,
dry_run = TRUE,
sites = "all",
release = "RELEASE-2023") {

if (!is.null(release)) {
file_dir2 <- paste(file_dir, release, sep = "/")
} else {
file_dir2 <- file_dir
}

if (get == TRUE) {

# script to pull down EC data files.
Expand Down Expand Up @@ -146,23 +151,22 @@ manage_local_EC_archive <- function(file_dir,

# get a vector of site months available for site i
if (!is.null(release)) {
releaseIndex <- unlist(available$data$siteCodes[[i]]$availableReleases)$release == release
releaseIndex <- which(
sapply(available$data$siteCodes[[i]]$availableReleases,
"[[",
1) == release)
site_months <- unlist(available$data$siteCodes[[i]]$availableReleases[[releaseIndex]]$availableMonths)
} else {
site_months <- unlist(available$data$siteCodes[[i]]$availableMonths)
}

# okay, check to see if data folder exists for site, otherwise create.
if (!is.null(release)) {
ifelse(!dir.exists(paste(file_dir, release, site_name, sep = "/")),
dir.create(paste(file_dir, release, site_name, sep = "/"),
recursive = TRUE),
FALSE)
} else {
ifelse(!dir.exists(paste(file_dir, site_name, sep = "/")),
dir.create(paste(file_dir, site_name, sep = "/")), FALSE)
}


ifelse(!dir.exists(paste(file_dir2, site_name, sep = "/")),
dir.create(paste(file_dir2, site_name, sep = "/"),
recursive = TRUE),
FALSE)

# okay - now loop through months and get the data files.
if (!is.null(length(site_months))) {

Expand Down Expand Up @@ -192,11 +196,11 @@ manage_local_EC_archive <- function(file_dir,
if (!length(dl_names[k]) == 0) {
if (!is.na(dl_names[k])) {
# check to see if file exists in folder
if (file.exists(paste0(file_dir,
if (file.exists(paste0(file_dir2, "/",
site_name,
"/",
dl_names[k])) |
file.exists(paste0(file_dir,
file.exists(paste0(file_dir2, "/",
site_name,
"/",
substr(dl_names[k],
Expand All @@ -210,7 +214,7 @@ manage_local_EC_archive <- function(file_dir,
} else { #doesn't exist, so download it.
print(paste("Downloading", dl_names[k]))
httr::GET(url = dl_urls[k],
httr::write_disk(paste0(file_dir,
httr::write_disk(paste0(file_dir2, "/",
site_name,
"/",
dl_names[k]),
Expand All @@ -231,7 +235,7 @@ manage_local_EC_archive <- function(file_dir,
# unzip files if requested.
if (get == TRUE & unzip_files == TRUE) {
# list the files in file_dir
files <- list.files(path = paste0(file_dir, "/"),
files <- list.files(path = paste0(file_dir2, "/"),
pattern = "*.gz",
recursive = TRUE,
full.names = TRUE)
Expand All @@ -245,7 +249,7 @@ manage_local_EC_archive <- function(file_dir,

if (trim == TRUE) {
# list the files in file_dir
files <- list.files(path = file_dir,
files <- list.files(path = file_dir2,
pattern = "*.h5",
recursive = TRUE,
full.names = TRUE)
Expand Down

0 comments on commit 0a89fa5

Please sign in to comment.