diff --git a/R/download.R b/R/download.R index 3d39a7b..0ba3b75 100644 --- a/R/download.R +++ b/R/download.R @@ -2279,7 +2279,7 @@ download_koppen_geiger <- function( #' @return #' * For \code{hash = FALSE}, NULL #' * For \code{hash = TRUE}, an \code{rlang::hash_file} character. -#' * HDF (.hdf) files will be stored in +#' * HDF (.hdf) files will be stored in year/day_of_year sub-directories within #' \code{directory_to_save}. #' @importFrom Rdpack reprompt #' @references @@ -2493,6 +2493,7 @@ download_modis <- function( nasa_earth_data_token, "\" -O ", directory_to_save, + splitter, download_name, "\n" ) @@ -2500,10 +2501,19 @@ download_modis <- function( #### filter commands to non-existing files download_command <- download_command[ which( - !file.exists(paste0(directory_to_save, download_name)) + !file.exists(paste0(directory_to_save, splitter, download_name)) ) ] + new_dirs <- unique( + sprintf("%s%s", directory_to_save, splitter) + ) + + lapply( + new_dirs, + function(x) dir.create(x, recursive = TRUE, showWarnings = FALSE) + ) + # avoid any possible errors by removing existing command files download_sink(commands_txt) #### cat command only if file does not already exist diff --git a/man/download_modis.Rd b/man/download_modis.Rd index 9e92cec..6c5945e 100644 --- a/man/download_modis.Rd +++ b/man/download_modis.Rd @@ -61,7 +61,7 @@ downloaded files. Default is \code{FALSE}.} \itemize{ \item For \code{hash = FALSE}, NULL \item For \code{hash = TRUE}, an \code{rlang::hash_file} character. -\item HDF (.hdf) files will be stored in +\item HDF (.hdf) files will be stored in year/day_of_year sub-directories within \code{directory_to_save}. } } diff --git a/tests/testthat/test-terraclimate.R b/tests/testthat/test-terraclimate.R index 2c6a9f5..ed42fe1 100644 --- a/tests/testthat/test-terraclimate.R +++ b/tests/testthat/test-terraclimate.R @@ -44,7 +44,7 @@ testthat::test_that("download_terraclimate (single year)", { # function parameters year <- 2019 variables <- "Precipitation" - directory_to_save <- paste0(tempdir(), "/terracclimate/") + directory_to_save <- paste0(tempdir(), "/terraclimate/") # run download function download_data(dataset_name = "terraclimate", year = year,