diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml index f511d092..a8d227bc 100644 --- a/.github/workflows/check-standard.yaml +++ b/.github/workflows/check-standard.yaml @@ -34,6 +34,12 @@ jobs: - uses: r-lib/actions/setup-pandoc@v2 + - name: Install wget on Windows + if: matrix.config.os == 'windows-latest' + run: | + choco install wget -y + shell: powershell + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} diff --git a/.github/workflows/test-coverage-local.yaml b/.github/workflows/test-coverage-local.yaml index 4fcca8b4..55b773b0 100644 --- a/.github/workflows/test-coverage-local.yaml +++ b/.github/workflows/test-coverage-local.yaml @@ -27,6 +27,7 @@ jobs: extra-packages: | any::pak any::covr + any::rstac needs: coverage - name: Cache C++ and R dependencies diff --git a/.gitignore b/.gitignore index 5d0c1078..6c137a14 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,5 @@ rsconnect/ /doc/ /Meta/ inst/doc -inst/extdata/air.2m \ No newline at end of file +inst/extdata/air.2m +inst/extdata/nasa/token.txt \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index aed18825..15d36d06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,16 @@ Package: amadeus -Title: A Machine for Data, Environments, and User Setup for Common Environmental and Climate Health Datasets -Version: 1.0.2 +Title: Accessing and Analyzing Large-Scale Environmental Data in R +Version: 1.0.3 Authors@R: c( person(given = "Mitchell", family = "Manware", role = c("aut", "ctb"), comment = c(ORCID = "0009-0003-6440-6106")), person(given = "Insang", family = "Song", role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-8732-3256")), person(given = "Eva", family = "Marques", role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-9817-6546")), person(given = "Mariana", family = "Alifa Kassien", role = c("aut", "ctb"), comment = c(ORCID = "0000-0003-2295-406X")), - person(given = "Kyle", family = "Messier", role = c("aut", "cre"), email = "kyle.messier@nih.gov", comment = c(ORCID = "0000-0001-9508-9623")) + person(given = "Kyle", family = "Messier", role = c("aut", "cre"), email = "kyle.messier@nih.gov", comment = c(ORCID = "0000-0001-9508-9623")), + person("Spatiotemporal Exposures and Toxicology Group", role = c("cph")) ) Maintainer: Kyle Messier -Description: Functions are designed to facilitate access to and utility with large scale, publicly available environmental data in R. The package contains functions for downloading raw data files from web URLs (download_data()), processing the raw data files into clean spatial objects (process_covariates()), and extracting values from the spatial data objects at point and polygon locations (calc_covariates()). These functions call a series of source-specific functions which are tailored to each data sources/datasets particular URL structure, data format, and spatial/temporal resolution. The functions are tested, versioned, and open source and open access. +Description: Functions are designed to facilitate access to and utility with large scale, publicly available environmental data in R. The package contains functions for downloading raw data files from web URLs (download_data()), processing the raw data files into clean spatial objects (process_covariates()), and extracting values from the spatial data objects at point and polygon locations (calc_covariates()). These functions call a series of source-specific functions which are tailored to each data sources/datasets particular URL structure, data format, and spatial/temporal resolution. The functions are tested, versioned, and open source and open access. For calc_sedc() method details, see Messier, Akita, and Serre (2012) . Depends: R (>= 4.1.0) Imports: dplyr, sf, sftime, stats, terra, methods, data.table, httr, rvest, exactextractr, utils, stringi, testthat (>= 3.0.0), parallelly, stars, future, future.apply, tidyr, rlang, nhdplusTools, archive, collapse, Rdpack Suggests: covr, withr, knitr, rmarkdown, lwgeom, FNN, doRNG, devtools, stringr, tigris diff --git a/R/calculate_covariates.R b/R/calculate_covariates.R index b434d497..ce7b4dea 100644 --- a/R/calculate_covariates.R +++ b/R/calculate_covariates.R @@ -1136,6 +1136,7 @@ calc_temporal_dummies <- #' @author Insang Song #' @references #' \insertRef{messier2012integrating}{amadeus} +#' #' \insertRef{web_sedctutorial_package}{amadeus} #' @examples #' library(terra) diff --git a/R/calculate_covariates_auxiliary.R b/R/calculate_covariates_auxiliary.R index 9996c5e0..d387460d 100644 --- a/R/calculate_covariates_auxiliary.R +++ b/R/calculate_covariates_auxiliary.R @@ -132,7 +132,7 @@ calc_setcolumns <- function( #' @param time placeholder #' @param time_type placeholder #' @param level placeholder -#' @return NULL +#' @return NULL; provides progress messages to R console. #' @keywords internal #' @export calc_message <- function( @@ -299,7 +299,7 @@ calc_time <- function( #' @param POSIXt logical(1). Should the time values in `covar` be of class #' `POSIXt`? If `FALSE`, the time values will be checked for integer class #' (year and year-month). -#' @return NULL +#' @return NULL; returns a stop error if `time` is wrong class #' @keywords internal #' @export # nolint start diff --git a/R/download.R b/R/download.R index 205d9a75..b35900db 100644 --- a/R/download.R +++ b/R/download.R @@ -37,19 +37,19 @@ #' * \code{\link{download_huc}}: `"huc"` #' * \code{\link{download_cropscape}}: `"cropscape"`, `"cdl"` #' * \code{\link{download_prism}}: `"prism"` -#' @return NULL +#' @return NULL; Data files will be downloaded and stored in respective +#' sub-directories within \code{directory_to_save}. File format and +#' sub-directory names depend on data source and dataset of interest. #' @examples -#' \dontrun{ #' download_data( #' dataset_name = "narr", #' variables = "weasd", #' year = c(2023, 2023), -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_commands = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE #' ) -#' } #' @export download_data <- function( @@ -152,17 +152,16 @@ download_data <- #' @references #' \insertRef{data_usepa2023airdata}{amadeus} #' @examples -#' \dontrun{ #' download_aqs( #' parameter_code = 88101, #' resolution_temporal = "daily", -#' year = c(2022, 2023), -#' directory_to_save = "./data", +#' year = c(2023, 2023), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } # nolint end #' @export download_aqs <- @@ -253,16 +252,11 @@ download_aqs <- cat(download_commands) #### 9. finish "..._curl_commands.txt" file sink() - #### 10. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 11. download data download_run( download = download, - system_command = system_command + commands_txt = commands_txt, + remove = remove_command ) #### 12. unzip data sapply( @@ -275,11 +269,6 @@ download_aqs <- remove = remove_zip, download_name = download_names ) - #### 13. remove command file - download_remove_command( - commands_txt = commands_txt, - remove = remove_command - ) } @@ -326,14 +315,13 @@ download_aqs <- #' @references #' \insertRef{article_omernik2014ecoregions}{amadeus} #' @examples -#' \dontrun{ #' download_ecoregion( -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export download_ecoregion <- function( epa_certificate_path = @@ -400,20 +388,12 @@ download_ecoregion <- function( } #### 11. finish "...curl_commands.txt" file sink() - #### 12. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 13. download data download_run( download = download, - system_command = system_command + commands_txt = commands_txt, + remove = remove_command ) - #### 14. remove download command - download_remove_command(commands_txt = commands_txt, - remove = remove_command) #### 15. unzip files download_unzip( file_name = download_name, @@ -455,16 +435,14 @@ download_ecoregion <- function( #' @references #' \insertRef{keller_description_2021}{amadeus} #' @examples -#' \dontrun{ #' download_geos( #' collection = "aqc_tavg_1hr_g1440x721_v1", -#' date = c("2024-01-01", "2024-01-05"), -#' directory_to_save = "./data", +#' date = c("2024-01-01", "2024-01-01"), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @export # nolint end # nolint start: cyclocomp @@ -581,18 +559,9 @@ download_geos <- function( } #### 9. finish "..._wget_commands.txt" file sink() - #### 10. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 11. download data download_run( download = download, - system_command = system_command - ) - download_remove_command( commands_txt = commands_txt, remove = remove_command ) @@ -632,16 +601,15 @@ download_geos <- function( #' @references #' \insertRef{danielson_global_2011}{amadeus} #' @examples -#' \dontrun{ #' download_gmted( #' statistic = "Breakline Emphasis", #' resolution = "7.5 arc-seconds", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export download_gmted <- function( statistic = c( @@ -730,19 +698,9 @@ download_gmted <- function( } #### 14. finish "..._curl_commands.txt" file sink() - #### 15. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 16. download data download_run( download = download, - system_command = system_command - ) - #### 17. Remove command file - download_remove_command( commands_txt = commands_txt, remove = remove_command ) @@ -783,109 +741,199 @@ download_gmted <- function( #' @importFrom Rdpack reprompt #' @references #' \insertRef{data_gmao_merra-inst1_2d_asm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-inst1_2d_int_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-inst1_2d_lfo_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-inst3_3d_asm_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-inst3_3d_aer_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-inst3_3d_asm_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-inst3_3d_chm_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-inst3_3d_gas_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-inst3_2d_gas_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-inst6_3d_ana_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-inst6_3d_ana_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-statD_2d_slv_Nx_m}{amadeus} +#' #' \insertRef{data_gmao_merra-statD_2d_slv_Nx_d}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_adg_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_aer_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_chm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_csp_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_flx_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_int_Nx}{amadeus} +#' #' \insertRef{pawson_merra-2_2020}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_lnd_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_ocn_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_rad_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg1_2d_slv_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_mst_Ne}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_trb_Ne}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_nav_Ne}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_cld_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_mst_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_rad_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_tdt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_trb_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_udt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_odt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_qdt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_asm_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_cld_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_mst_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_3d_rad_Nv}{amadeus} +#' #' \insertRef{data_gmao_merra-tavg3_2d_glc_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instM_2d_asm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instM_2d_int_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instM_2d_lfo_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instM_2d_gas_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instM_3d_asm_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-instM_3d_ana_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_adg_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_aer_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_chm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_csp_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_flx_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_int_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_lfo_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_lnd_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_ocn_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_rad_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_slv_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_2d_glc_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_cld_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_mst_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_rad_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_tdt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_trb_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_udt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_odt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgM_3d_qdt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-const_2d_asm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instU_2d_asm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instU_2d_int_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instU_2d_lfo_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instU_2d_gas_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-instU_3d_asm_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-instU_3d_ana_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_adg_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_aer_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_chm_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_csp_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_flx_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_int_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_lfo_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_lnd_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_ocn_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_rad_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_slv_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_2d_glc_Nx}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_cld_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_mst_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_rad_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_tdt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_trb_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_udt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_odt_Np}{amadeus} +#' #' \insertRef{data_gmao_merra-tavgU_3d_qdt_Np}{amadeus} #' @examples -#' \dontrun{ #' download_merra2( #' collection = "inst1_2d_int_Nx", -#' date = c("2024-01-01", "2024-01-05"), -#' directory_to_save = "./data", +#' date = c("2024-01-01", "2024-01-01"), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @export # nolint end # nolint start: cyclocomp @@ -1150,19 +1198,9 @@ download_merra2 <- function( } #### finish "..._wget_commands.txt" sink() - #### build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### download data download_run( download = download, - system_command = system_command - ) - #### Remove command file - download_remove_command( commands_txt = commands_txt, remove = remove_command ) @@ -1195,16 +1233,14 @@ download_merra2 <- function( #' @references #' \insertRef{mesinger_north_2006}{amadeus} #' @examples -#' \dontrun{ #' download_narr( #' variables = c("weasd", "omega"), -#' year = c(2022, 2023), -#' directory_to_save = "./data", +#' year = c(2023, 2023), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @export # nolint end # nolint start: cyclocomp @@ -1294,19 +1330,9 @@ download_narr <- function( } #### 9. finish "..._curl_commands.txt" sink() - #### 10. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 11. download data download_run( download = download, - system_command = system_command - ) - #### 12. remove command text file - download_remove_command( commands_txt = commands_txt, remove = remove_command ) @@ -1345,19 +1371,18 @@ download_narr <- function( #' respective sub-directories within \code{directory_to_save}. #' @importFrom Rdpack reprompt #' @references -#' \insertRef{dewitz_national_2023}{amadeus} +#' \insertRef{dewitz_national_2023}{amadeus}
#' \insertRef{dewitz_national_2024}{amadeus} #' @examples -#' \dontrun{ #' download_nlcd( #' collection = "Coterminous United States", #' year = 2021, -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export download_nlcd <- function( collection = "Coterminous United States", @@ -1446,16 +1471,11 @@ download_nlcd <- function( } #### 13. finish "..._curl_command.txt" sink() - #### 14. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 15. download data download_run( download = download, - system_command = system_command + commands_txt = commands_txt, + remove = remove_command ) #### 16. end if unzip == FALSE download_unzip( @@ -1468,11 +1488,6 @@ download_nlcd <- function( remove = remove_zip, download_name = download_name ) - #### 18. remove command text - download_remove_command( - commands_txt = commands_txt, - remove = remove_command - ) } # nolint start @@ -1506,16 +1521,15 @@ download_nlcd <- function( #' @references #' \insertRef{data_ciesin2013groads}{amadeus} #' @examples -#' \dontrun{ #' download_sedac_groads( #' data_region = "Americas", #' data_format = "Shapefile", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export download_sedac_groads <- function( data_region = c("Americas", "Global", "Africa", "Asia", "Europe", "Oceania East", "Oceania West"), @@ -1600,16 +1614,11 @@ download_sedac_groads <- function( } #### 13. finish "..._curl_commands.txt" file sink() - #### 14. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 15. download data download_run( download = download, - system_command = system_command + commands_txt = commands_txt, + remove = remove_command ) #### 16. end if unzip == FALSE download_unzip( @@ -1617,11 +1626,6 @@ download_sedac_groads <- function( directory_to_unzip = directory_to_save, unzip = unzip ) - #### 17. Remove command file - download_remove_command( - commands_txt = commands_txt, - remove = remove_command - ) #### 18. remove zip files download_remove_zips( remove = remove_zip, @@ -1664,17 +1668,16 @@ download_sedac_groads <- function( #' @references #' \insertRef{data_ciesin2017gpwv4}{amadeus} #' @examples -#' \dontrun{ #' download_sedac_population( #' data_resolution = "30 second", #' data_format = "GeoTIFF", #' year = "2020", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export download_sedac_population <- function( data_resolution = "60 minute", @@ -1792,16 +1795,11 @@ download_sedac_population <- function( } #### 14. finish "..._curl_commands.txt" file sink() - #### 15. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 16. download data download_run( download = download, - system_command = system_command + commands_txt = commands_txt, + remove = remove_command ) #### 17. end if unzip == FALSE download_unzip( @@ -1809,11 +1807,6 @@ download_sedac_population <- function( directory_to_unzip = directory_to_save, unzip = unzip ) - #### 18. Remove command file - download_remove_command( - commands_txt = commands_txt, - remove = remove_command - ) #### 19. remove zip files download_remove_zips( remove = remove_zip, @@ -1858,16 +1851,15 @@ download_sedac_population <- function( #' @references #' \insertRef{web_HMSabout}{amadeus} #' @examples -#' \dontrun{ #' download_hms( #' data_format = "Shapefile", -#' date = c("2024-01-01", "2024-01-05"), -#' directory_to_save = "./data", +#' date = c("2024-01-01", "2024-01-01"), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export # nolint start: cyclocomp download_hms <- function( @@ -1974,21 +1966,11 @@ download_hms <- function( } #### 9. finish "..._curl_commands.txt" sink() - #### 10. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 11. download data download_run( download = download, - system_command = system_command - ) - #### 12. remove command file - download_remove_command( - remove = remove_command, - commands_txt = commands_txt + commands_txt = commands_txt, + remove = remove_command ) #### 13. end if data_format == "KML" if (data_format == "KML") { @@ -2046,18 +2028,18 @@ download_hms <- function( #' @importFrom Rdpack reprompt #' @references #' \insertRef{article_beck2023koppen}{amadeus} +#' #' \insertRef{article_beck2018present}{amadeus} #' @examples -#' \dontrun{ #' download_koppen_geiger( #' data_resolution = "0.0083", #' time_period = "Present", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } # nolint end #' @export download_koppen_geiger <- function( @@ -2126,19 +2108,9 @@ download_koppen_geiger <- function( cat(download_command) } sink() - #### 14. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 15. download data download_run( download = download, - system_command = system_command - ) - #### 17. Remove command file - download_remove_command( commands_txt = commands_txt, remove = remove_command ) @@ -2180,7 +2152,7 @@ download_koppen_geiger <- function( #' Token for downloading data from NASA. Should be set before #' trying running the function. #' @param mod06_links character(1). CSV file path to MOD06_L2 download links -#' from NASA LPDAAC. Default is `NULL`. +#' from [NASA LAADS MOD06_L2](https://ladsweb.modaps.eosdis.nasa.gov/search/order/2/MOD06_L2--61). Default is `NULL`. #' @param date character(2). length of 10 each. Start/end date for downloading data. #' Format "YYYY-MM-DD" (ex. January 1, 2018 = `"2018-01-01"`). Note: ignored if #' \code{product == "MOD06_L2"}. @@ -2198,55 +2170,65 @@ download_koppen_geiger <- function( #' @importFrom Rdpack reprompt #' @references #' \insertRef{data_mcd19a22021}{amadeus} +#' #' \insertRef{data_mod06l2_2017}{amadeus} +#' #' \insertRef{data_mod09ga2021}{amadeus} +#' #' \insertRef{data_mod11a12021}{amadeus} +#' #' \insertRef{data_mod13a22021}{amadeus} +#' #' \insertRef{article_roman2018vnp46}{amadeus} -# nolint end #' @examples -#' \dontrun{ -#' # example with MOD0GA product +#' # example with MOD09GA product #' download_modis( #' product = "MOD09GA", #' version = "61", -#' horizontal_tiles = c(8, 10), -#' vertical_tiles = c(4, 5), -#' date = c("2024-01-01", "2024-01-10"), -#' nasa_earth_data_token = readLines("~/pre_generated_token.txt"), -#' directory_to_save = "./data/mod09ga", +#' horizontal_tiles = c(8, 8), +#' vertical_tiles = c(4, 4), +#' date = c("2024-01-01", "2024-01-01"), +#' nasa_earth_data_token = +#' system.file("extdata", "nasa", "token.txt", package = "amadeus"), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) #' # example with MOD06_L2 product #' download_modis( #' product = "MOD06_L2", #' version = "61", -#' horizontal_tiles = c(8, 10), -#' vertical_tiles = c(4, 5), -#' mod06_links = "~/LAADS_query.2024-07-15T12_17.csv", -#' date = c("2024-01-01", "2024-01-10"), -#' nasa_earth_data_token = readLines("~/pre_generated_token.txt"), -#' directory_to_save = "./data/mod06l2", +#' horizontal_tiles = c(8, 8), +#' vertical_tiles = c(4, 4), +#' date = c("2024-01-01", "2024-01-01"), +#' mod06_links = +#' system.file( +#' "extdata", "nasa", "LAADS_query.2024-08-02T12_49.csv", +#' package = "amadeus" +#' ), +#' nasa_earth_data_token = +#' system.file("extdata", "nasa", "token.txt", package = "amadeus"), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) #' # example with VNP46A2 product #' download_modis( #' product = "VNP46A2", #' version = "61", -#' horizontal_tiles = c(8, 10), -#' vertical_tiles = c(4, 5), -#' date = c("2024-01-01", "2024-01-10"), -#' nasa_earth_data_token = readLines("~/pre_generated_token.txt"), -#' directory_to_save = "./data/vnp46a2", +#' horizontal_tiles = c(8, 8), +#' vertical_tiles = c(4, 4), +#' date = c("2024-01-01", "2024-01-01"), +#' nasa_earth_data_token = +#' system.file("extdata", "nasa", "token.txt", package = "amadeus"), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } +# nolint end #' @export download_modis <- function( product = c( @@ -2411,22 +2393,13 @@ download_modis <- function( cat(download_command) sink() - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) download_run( download = download, - system_command = system_command - ) - - message("Requests were processed.\n") - - download_remove_command( commands_txt = commands_txt, remove = remove_command ) + + message("Requests were processed.\n") return(NULL) } @@ -2544,21 +2517,12 @@ download_modis <- function( sink(file = NULL) #### 17. - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) download_run( download = download, - system_command = system_command + commands_txt = commands_txt, + remove = remove_command ) - message("Requests were processed.\n") - - download_remove_command(commands_txt = commands_txt, - remove = remove_command) - } @@ -2585,15 +2549,13 @@ download_modis <- function( #' @references #' \insertRef{web_usepa2024tri}{amadeus} #' @examples -#' \dontrun{ #' download_tri( -#' year = c(2020L, 2021L), -#' directory_to_save = "./data", +#' year = c(2021L, 2021L), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @export download_tri <- function( year = c(2018L, 2022L), @@ -2649,19 +2611,13 @@ download_tri <- function( writeLines(download_commands) #### 7. finish "..._curl_commands.txt" file sink() - #### 8. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 9. download data - download_run(download = download, - system_command = system_command) + download_run( + download = download, + commands_txt = commands_txt, + remove = remove_command + ) message("Requests were processed.\n") - #### 10. remove download commands - download_remove_command(commands_txt = commands_txt, - remove = remove_command) } @@ -2708,15 +2664,14 @@ download_tri <- function( #' @references #' \insertRef{web_usepa2024nei}{amadeus} #' @examples -#' \dontrun{ #' download_nei( #' year = c(2017L, 2020L), -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export download_nei <- function( epa_certificate_path = @@ -2788,15 +2743,12 @@ download_nei <- function( writeLines(download_commands) #### 7. finish "..._curl_commands.txt" file sink() - #### 8. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 9. download data - download_run(download = download, - system_command = system_command) + download_run( + download = download, + commands_txt = commands_txt, + remove = remove_command + ) #### 10. unzip data # note that this part does not utilize download_unzip @@ -2813,10 +2765,6 @@ download_nei <- function( } } message("Requests were processed.\n") - #### 10. remove download commands - download_remove_command(commands_txt = commands_txt, - remove = remove_command) - } @@ -2847,22 +2795,21 @@ download_nei <- function( #' the text file containing download commands. #' @param unzip logical(1). Unzip the downloaded compressed files. #' Default is \code{FALSE}. Not working for this function since HUC data is in 7z format. -#' @return NULL. Downloaded files will be stored in \code{directory_to_save}. +#' @return NULL; Downloaded files will be stored in \code{directory_to_save}. #' @author Insang Song #' @importFrom Rdpack reprompt #' @references #' \insertRef{data_usgs2023nhd}{amadeus} #' @examples -#' \dontrun{ #' download_huc( #' region = "Lower48", #' type = "Seamless", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @export # @importFrom archive archive_extract download_huc <- @@ -2937,15 +2884,12 @@ download_huc <- writeLines(download_commands) #### 7. finish "..._curl_commands.txt" file sink() - #### 8. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 9. download data - download_run(download = download, - system_command = system_command) + download_run( + download = download, + commands_txt = commands_txt, + remove = remove_command + ) #### 10. unzip data # note that this part does not utilize download_unzip @@ -2963,10 +2907,6 @@ download_huc <- } } message("Requests were processed.\n") - #### 10. remove download commands - download_remove_command(commands_txt = commands_txt, - remove = remove_command) - } # nolint end @@ -3000,16 +2940,15 @@ download_huc <- #' @return NULL; Yearly comma-separated value (CSV) files will be stored in #' \code{directory_to_save}. #' @examples -#' \dontrun{ #' download_cropscape( #' year = 2020, #' source = "USDA", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, -#' remove_command = TRUE +#' download = FALSE, # NOTE: download skipped for examples, +#' remove_command = TRUE, +#' unzip = FALSE #' ) -#' } #' @importFrom archive archive_extract #' @export download_cropscape <- function( @@ -3077,15 +3016,12 @@ download_cropscape <- function( writeLines(download_commands) #### 7. finish "..._curl_commands.txt" file sink() - #### 8. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 9. download data - download_run(download = download, - system_command = system_command) + download_run( + download = download, + commands_txt = commands_txt, + remove = remove_command + ) #### 10. unzip data # note that this part does not utilize download_unzip @@ -3102,9 +3038,6 @@ download_cropscape <- function( # nocov end } message("Requests were processed.\n") - #### 10. remove download commands - download_remove_command(commands_txt = commands_txt, - remove = remove_command) } # nolint end @@ -3151,18 +3084,16 @@ download_cropscape <- function( #' @references #' \insertRef{article_daly2000prism}{amadeus} #' @examples -#' \dontrun{ #' download_prism( #' time = "202104", #' element = "ppt", #' data_type = "ts", #' format = "nc", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @references #' * [PRISM Climate Group](https://prism.oregonstate.edu/) #' * [PRISM Web Service Guide](https://prism.oregonstate.edu/documents/PRISM_downloads_web_service.pdf) @@ -3244,21 +3175,13 @@ download_prism <- function( writeLines(download_commands) #### 7. finish "..._curl_commands.txt" file sink() - #### 8. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 9. download data - download_run(download = download, - system_command = system_command) - + download_run( + download = download, + commands_txt = commands_txt, + remove = remove_command + ) message("Requests were processed.\n") - #### 10. remove download commands - download_remove_command(commands_txt = commands_txt, - remove = remove_command) - } # nolint start @@ -3287,16 +3210,14 @@ download_prism <- function( #' @references #' \insertRef{article_abatzoglou2013development}{amadeus} #' @examples -#' \dontrun{ #' download_gridmet( #' variables = "Precipitation", -#' year = c(2023, 2024), -#' directory_to_save = "./data", +#' year = c(2023, 2023), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @export # nolint end download_gridmet <- function( @@ -3386,19 +3307,9 @@ download_gridmet <- function( } #### finish "..._curl_commands.txt" sink() - #### build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### download data download_run( download = download, - system_command = system_command - ) - #### remove command text file - download_remove_command( commands_txt = commands_txt, remove = remove_command ) @@ -3429,16 +3340,14 @@ download_gridmet <- function( #' @references #' \insertRef{article_abatzoglou2018terraclimate}{amadeus} #' @examples -#' \dontrun{ #' download_terraclimate( #' variables = "Precipitation", -#' year = c(2023, 2024), -#' directory_to_save = "./data", +#' year = c(2023, 2023), +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, -#' download = TRUE, +#' download = FALSE, # NOTE: download skipped for examples, #' remove_command = TRUE #' ) -#' } #' @export # nolint end download_terraclimate <- function( @@ -3529,19 +3438,9 @@ download_terraclimate <- function( } #### finish "..._curl_commands.txt" sink() - #### build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### download data download_run( download = download, - system_command = system_command - ) - #### remove command text file - download_remove_command( commands_txt = commands_txt, remove = remove_command ) diff --git a/R/download_auxiliary.R b/R/download_auxiliary.R index acbdfccf..df2327ce 100644 --- a/R/download_auxiliary.R +++ b/R/download_auxiliary.R @@ -77,7 +77,7 @@ download_sanitize_path <- #' The \code{acknowledgement} parameter is designed to help users avoid #' accidentally initiating a very large data download that may take a very long #' time to run or exceed machine capabilities. -#' @return NULL +#' @return NULL; returns a stop error if the acknowledgement is FALSE #' @keywords internal #' @export download_permit <- @@ -99,22 +99,40 @@ download_permit <- #' produced by one of the data download functions. #' @param download logical(1). Execute (\code{TRUE}) or #' skip (\code{FALSE}) download. -#' @param system_command character(1). Linux command to execute downloads. -#' Inherited from data download function. -#' @return NULL +#' @param commands_txt character(1). Path of download commands +#' @param remove logical(1). Remove (\code{TRUE}) or +#' keep (\code{FALSE}) command. Passed to \code{download_remove_commands}. +#' @return NULL; runs download commands with shell (Unix/Linux) or +#' command prompt (Windows) and removes \code{commands_txt} file if +#' \code{remove = TRUE}. #' @keywords internal #' @export download_run <- function( download = FALSE, - system_command = NULL) { + commands_txt = NULL, + remove = FALSE) { + if (tolower(.Platform$OS.type) == "windows") { + # nocov start + runner <- "" + commands_bat <- gsub(".txt", ".bat", commands_txt) + file.rename(commands_txt, commands_bat) + commands_txt <- commands_bat + # nocov end + } else { + runner <- ". " + } + system_command <- paste0(runner, commands_txt) if (download == TRUE) { message(paste0("Downloading requested files...\n")) - system(command = system_command) + system(command = system_command, intern = TRUE) message(paste0("Requested files have been downloaded.\n")) } else { message(paste0("Skipping data download.\n")) - return(NULL) } + download_remove_command( + commands_txt = commands_txt, + remove = remove + ) } @@ -124,7 +142,7 @@ download_run <- function( #' @param commands_txt character(1). Path of download commands #' @param remove logical(1). Remove (\code{TRUE}) or #' keep (\code{FALSE}) commands -#' @return NULL +#' @return NULL; removes .txt/.bat file storing all download commands. #' @keywords internal #' @export download_remove_command <- @@ -140,7 +158,8 @@ download_remove_command <- #' @description #' Open connection to \code{command_txt} file to store download commands. #' @param command_txt character(1). file path to export commands. -#' @return NULL +#' @return NULL; creates and opens connection to text file to store +#' download commands #' @keywords internal #' @export download_sink <- @@ -159,7 +178,7 @@ download_sink <- #' @param directory_to_unzip character(1). Directory to unzip #' data #' @param unzip logical(1). Unzip (\code{TRUE}) or not. -#' @return NULL +#' @return NULL; unzips downloaded zip files #' @keywords internal #' @export download_unzip <- @@ -193,7 +212,7 @@ download_unzip <- #' If \code{remove = TRUE}, ensure that \code{unzip = TRUE}. Choosing to remove #' ".zip" files without unzipping will retain none of the downloaded data. #' then it will remove all files in the second higher level directory. -#' @return NULL +#' @return NULL; removes downloaded zip files after they are unzipped #' @keywords internal #' @export download_remove_zips <- @@ -205,7 +224,7 @@ download_remove_zips <- file.remove(download_name) # oftentimes zipfiles are stored in zip_files under # directory_to_save in download functions. - unlink(dirname(dirname(download_name)), recursive = TRUE) + unlink(dirname(download_name), recursive = TRUE) message(paste0("Download files removed.\n")) } } @@ -216,7 +235,8 @@ download_remove_zips <- #' Check that all parameters have been assigned a value. #' @param parameters parameters passed to function (called by #' \code{mget(ls())}.) -#' @return NULL +#' @return NULL; returns a stop error if one or more function +#' parameters other than 'extent' are NULL #' @keywords internal #' @export check_for_null_parameters <- @@ -434,7 +454,7 @@ check_urls <- function( #' @param commands_path file path with download commands #' @param url_status logical vector for URL status = 200 #' @importFrom testthat expect_true -#' @return NULL +#' @return NULL; returns stop error if one or more tests fail #' @keywords internal #' @export test_download_functions <- function( diff --git a/R/manipulate_spacetime_data.R b/R/manipulate_spacetime_data.R index 0bcd5cc0..973ff257 100644 --- a/R/manipulate_spacetime_data.R +++ b/R/manipulate_spacetime_data.R @@ -6,7 +6,8 @@ #' @import sftime #' @author Eva Marques #' @keywords spacetime -#' @return NULL +#' @return NULL; returns stop error if \code{x} does not match class +#' and column expectations #' @export check_mysftime <- function(x) { stopifnot( @@ -29,7 +30,8 @@ check_mysftime <- function(x) { #' @import sf #' @author Eva Marques #' @keywords spacetime -#' @return NULL +#' @return NULL; returns stop error if \code{x} does not match class +#' and/or column expectations #' @export check_mysf <- function(x) { stopifnot( diff --git a/R/olm_functions.R b/R/olm_functions.R index 7bec7838..83ed8457 100644 --- a/R/olm_functions.R +++ b/R/olm_functions.R @@ -104,7 +104,7 @@ #' download_olm( #' product = "no2_s5p.l3.trop.tmwm", #' format = "tif", -#' directory_to_save = "./data", +#' directory_to_save = tempdir(), #' acknowledgement = TRUE, #' download = TRUE, #' remove_command = TRUE @@ -160,21 +160,13 @@ download_olm <- function( writeLines(download_commands) #### 7. finish "..._curl_commands.txt" file sink() - #### 8. build system command - system_command <- paste0( - ". ", - commands_txt, - "\n" - ) #### 9. download data - download_run(download = download, - system_command = system_command) - + download_run( + download = download, + commands_txt = commands_txt, + remove = remove_command + ) message("Requests were processed.\n") - #### 10. remove download commands - download_remove_command(commands_txt = commands_txt, - remove = remove_command) - } diff --git a/R/process.R b/R/process.R index 7beaf8ac..09b5830e 100644 --- a/R/process.R +++ b/R/process.R @@ -37,11 +37,11 @@ #' @author Insang Song #' @examples #' \dontrun{ -#' narr <- process_covariates( +#' process_covariates( #' covariate = "narr", -#' date = c("2023-01-01", "2023-01-10"), +#' date = c("2018-01-01", "2018-01-01"), #' variable = "weasd", -#' path = "./data/weasd" +#' path = system.file("extdata", "examples", "narr", "weasd") #' ) #' } #' @export @@ -1777,10 +1777,10 @@ process_gmted <- function( #' @importFrom stringi stri_pad #' @examples #' \dontrun{ -#' narr <- process_narr( -#' date = c("2022-01-01", "2022-01-10"), +#' process_narr( +#' date = c("2018-01-01", "2018-01-01"), #' variable = "weasd", -#' path = "./data/weasd" +#' path = "./tests/testdata/narr/weasd" #' ) #' } #' @export diff --git a/inst/extdata/nasa/LAADS_query.2024-08-02T12_49.csv b/inst/extdata/nasa/LAADS_query.2024-08-02T12_49.csv new file mode 100644 index 00000000..108de8f6 --- /dev/null +++ b/inst/extdata/nasa/LAADS_query.2024-08-02T12_49.csv @@ -0,0 +1,29 @@ +fileId,fileUrls from query MOD06_L2--61 2024-01-01..2024-01-01 x-130y52 x-60y20[7],size +7911766596,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0000.061.2024004163458.hdf,25621588 +7911768252,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0630.061.2024004163743.hdf,24422091 +7911800062,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1825.061.2024004170824.hdf,110903962 +7911805131,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1830.061.2024004171501.hdf,83971543 +7911807156,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0455.061.2024004171751.hdf,26383015 +7911817538,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0625.061.2024004172824.hdf,15698686 +7911824357,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0315.061.2024004173252.hdf,27324693 +7911825047,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0445.061.2024004173314.hdf,22231646 +7911825048,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0450.061.2024004173317.hdf,21401919 +7911826681,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1325.061.2024004173417.hdf,49119679 +7911831965,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0135.061.2024004173901.hdf,19161583 +7911831967,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1505.061.2024004173909.hdf,70886596 +7911852817,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1655.061.2024004175230.hdf,92096215 +7911853382,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1515.061.2024004175255.hdf,103871050 +7911856257,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1330.061.2024004175535.hdf,151563177 +7911861741,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1835.061.2024004175944.hdf,151909358 +7912213770,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0125.061.2024004220733.hdf,15604706 +7912221566,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.2000.061.2024004221242.hdf,49000824 +7912229320,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0130.061.2024004221757.hdf,19276866 +7912229322,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1645.061.2024004221716.hdf,94529989 +7912233097,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0635.061.2024004222042.hdf,24651713 +7912234978,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1650.061.2024004222223.hdf,106852710 +7912235847,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0305.061.2024004222324.hdf,17854548 +7912244880,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.2005.061.2024004223112.hdf,151953394 +7912246082,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0310.061.2024004223204.hdf,21708427 +7912256697,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.0140.061.2024004223730.hdf,23658002 +7912264423,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1510.061.2024004224117.hdf,153765318 +7912281941,/archive/allData/61/MOD06_L2/2024/001/MOD06_L2.A2024001.1335.061.2024004225258.hdf,119616777 diff --git a/man/calc_check_time.Rd b/man/calc_check_time.Rd index 9099defb..136a8e20 100644 --- a/man/calc_check_time.Rd +++ b/man/calc_check_time.Rd @@ -13,6 +13,9 @@ calc_check_time(covar, POSIXt = TRUE) \code{POSIXt}? If \code{FALSE}, the time values will be checked for integer class (year and year-month).} } +\value{ +NULL; returns a stop error if \code{time} is wrong class +} \description{ Check the time values within calculated covariates \code{data.frame} } diff --git a/man/calc_message.Rd b/man/calc_message.Rd index e0bb2f10..11eb2f52 100644 --- a/man/calc_message.Rd +++ b/man/calc_message.Rd @@ -17,6 +17,9 @@ calc_message(dataset, variable, time, time_type, level) \item{level}{placeholder} } +\value{ +NULL; provides progress messages to R console. +} \description{ Send messages updating covariate extraction progress. } diff --git a/man/calc_sedc.Rd b/man/calc_sedc.Rd index bfd717bd..14ee8b8c 100644 --- a/man/calc_sedc.Rd +++ b/man/calc_sedc.Rd @@ -73,6 +73,7 @@ calc_sedc(pnt_locs, pnt_from, "NAME", 1e4, vals) } \references{ \insertRef{messier2012integrating}{amadeus} + \insertRef{web_sedctutorial_package}{amadeus} } \author{ diff --git a/man/check_for_null_parameters.Rd b/man/check_for_null_parameters.Rd index e2a6fbef..d1fdb2ae 100644 --- a/man/check_for_null_parameters.Rd +++ b/man/check_for_null_parameters.Rd @@ -10,6 +10,10 @@ check_for_null_parameters(parameters) \item{parameters}{parameters passed to function (called by \code{mget(ls())}.)} } +\value{ +NULL; returns a stop error if one or more function +parameters other than 'extent' are NULL +} \description{ Check that all parameters have been assigned a value. } diff --git a/man/check_mysf.Rd b/man/check_mysf.Rd index 1d022802..650b0cf6 100644 --- a/man/check_mysf.Rd +++ b/man/check_mysf.Rd @@ -9,6 +9,10 @@ check_mysf(x) \arguments{ \item{x}{an \code{sf} object} } +\value{ +NULL; returns stop error if \code{x} does not match class +and/or column expectations +} \description{ Check an \code{sf} object for its class, \code{$geometry} column, and geometry class. diff --git a/man/check_mysftime.Rd b/man/check_mysftime.Rd index be7cf39a..e13e7db8 100644 --- a/man/check_mysftime.Rd +++ b/man/check_mysftime.Rd @@ -9,6 +9,10 @@ check_mysftime(x) \arguments{ \item{x}{an \code{sftime} object} } +\value{ +NULL; returns stop error if \code{x} does not match class +and column expectations +} \description{ Check an \code{sftime} object for its class, \code{$time} column, \code{$geometry} column, and geometry class. diff --git a/man/download_aqs.Rd b/man/download_aqs.Rd index 6fda80ed..0b5de91a 100644 --- a/man/download_aqs.Rd +++ b/man/download_aqs.Rd @@ -60,18 +60,17 @@ NULL; Zip and/or data files will be downloaded and stored in The \code{download_aqs()} function accesses and downloads Air Quality System (AQS) data from the \href{https://aqs.epa.gov/aqsweb/airdata/download_files.html}{U.S. Environmental Protection Agency's (EPA) Pre-Generated Data Files}. } \examples{ -\dontrun{ download_aqs( parameter_code = 88101, resolution_temporal = "daily", - year = c(2022, 2023), - directory_to_save = "./data", + year = c(2023, 2023), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{data_usepa2023airdata}{amadeus} } diff --git a/man/download_cropscape.Rd b/man/download_cropscape.Rd index 759e6be2..05758243 100644 --- a/man/download_cropscape.Rd +++ b/man/download_cropscape.Rd @@ -54,17 +54,16 @@ the \href{https://www.nass.usda.gov/Research_and_Science/Cropland/Release/index. JSON files should be found at STAC catalog of OpenLandMap } \examples{ -\dontrun{ download_cropscape( year = 2020, source = "USDA", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \author{ Insang Song } diff --git a/man/download_data.Rd b/man/download_data.Rd index 8717fc23..8cb944bd 100644 --- a/man/download_data.Rd +++ b/man/download_data.Rd @@ -26,6 +26,11 @@ large and use lots of machine storage and memory.} \item{...}{Arguments passed to each download function.} } +\value{ +NULL; Data files will be downloaded and stored in respective +sub-directories within \code{directory_to_save}. File format and +sub-directory names depend on data source and dataset of interest. +} \description{ The \code{download_data()} function accesses and downloads atmospheric, meteorological, and environmental data from various open-access data sources. } @@ -35,18 +40,16 @@ The \code{download_data()} function accesses and downloads atmospheric, meteorol } } \examples{ -\dontrun{ download_data( dataset_name = "narr", variables = "weasd", year = c(2023, 2023), - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_commands = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE ) } -} \seealso{ For details of each download function per dataset, Please refer to: diff --git a/man/download_ecoregion.Rd b/man/download_ecoregion.Rd index e73adbe1..4066e864 100644 --- a/man/download_ecoregion.Rd +++ b/man/download_ecoregion.Rd @@ -65,15 +65,14 @@ certificate updates in the future. } } \examples{ -\dontrun{ download_ecoregion( - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{article_omernik2014ecoregions}{amadeus} } diff --git a/man/download_geos.Rd b/man/download_geos.Rd index 7c4f06bc..1a1fabfb 100644 --- a/man/download_geos.Rd +++ b/man/download_geos.Rd @@ -46,17 +46,15 @@ The \code{download_geos()} function accesses and downloads various atmospheric composition collections from \href{https://gmao.gsfc.nasa.gov/GEOS_systems/}{NASA's Global Earth Observing System (GEOS) model}. } \examples{ -\dontrun{ download_geos( collection = "aqc_tavg_1hr_g1440x721_v1", - date = c("2024-01-01", "2024-01-05"), - directory_to_save = "./data", + date = c("2024-01-01", "2024-01-01"), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{keller_description_2021}{amadeus} } diff --git a/man/download_gmted.Rd b/man/download_gmted.Rd index 3b07e148..7299a83c 100644 --- a/man/download_gmted.Rd +++ b/man/download_gmted.Rd @@ -55,17 +55,16 @@ Multi-resolution Terrain Elevation Data (GMTED2010) from \href{https://www.usgs.gov/coastal-changes-and-impacts/gmted2010}{U.S. Geological Survey and National Geospatial-Intelligence Agency}. } \examples{ -\dontrun{ download_gmted( statistic = "Breakline Emphasis", resolution = "7.5 arc-seconds", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{danielson_global_2011}{amadeus} } diff --git a/man/download_gridmet.Rd b/man/download_gridmet.Rd index f8b34a50..f4082abd 100644 --- a/man/download_gridmet.Rd +++ b/man/download_gridmet.Rd @@ -43,17 +43,15 @@ folder within \code{directory_to_save}. The \code{download_gridmet} function accesses and downloads gridded surface meteorological data from the \href{https://www.climatologylab.org/gridmet.html}{University of California Merced Climatology Lab's gridMET dataset}. } \examples{ -\dontrun{ download_gridmet( variables = "Precipitation", - year = c(2023, 2024), - directory_to_save = "./data", + year = c(2023, 2023), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{article_abatzoglou2013development}{amadeus} } diff --git a/man/download_hms.Rd b/man/download_hms.Rd index 20c280e7..fe92479d 100644 --- a/man/download_hms.Rd +++ b/man/download_hms.Rd @@ -55,17 +55,16 @@ The \code{download_hms()} function accesses and downloads wildfire smoke plume coverage data from \href{https://www.ospo.noaa.gov/products/land/hms.html#0}{NOAA's Hazard Mapping System Fire and Smoke Product}. } \examples{ -\dontrun{ download_hms( data_format = "Shapefile", - date = c("2024-01-01", "2024-01-05"), - directory_to_save = "./data", + date = c("2024-01-01", "2024-01-01"), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{web_HMSabout}{amadeus} } diff --git a/man/download_huc.Rd b/man/download_huc.Rd index 3b882826..742b0b48 100644 --- a/man/download_huc.Rd +++ b/man/download_huc.Rd @@ -38,7 +38,7 @@ the text file containing download commands.} Default is \code{FALSE}. Not working for this function since HUC data is in 7z format.} } \value{ -NULL. Downloaded files will be stored in \code{directory_to_save}. +NULL; Downloaded files will be stored in \code{directory_to_save}. } \description{ NHDPlus data provides the most comprehensive and high-resolution @@ -52,17 +52,16 @@ For whom wants to download a specific region, please visit \href{https://www.epa.gov/waterdata/get-nhdplus-national-hydrography-dataset-plus-data#ListofAreas}{Get NHDPlus Data} } \examples{ -\dontrun{ download_huc( region = "Lower48", type = "Seamless", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{data_usgs2023nhd}{amadeus} } diff --git a/man/download_koppen_geiger.Rd b/man/download_koppen_geiger.Rd index a0043815..1d4b7bc2 100644 --- a/man/download_koppen_geiger.Rd +++ b/man/download_koppen_geiger.Rd @@ -56,19 +56,19 @@ Köppen-Geiger climate classification maps at 1-km resolution}(\href{https://www.nature.com/articles/sdata2018214}{link for article}; \href{https://figshare.com/articles/dataset/Present_and_future_K_ppen-Geiger_climate_classification_maps_at_1-km_resolution/6396959/2}{link for data}). } \examples{ -\dontrun{ download_koppen_geiger( data_resolution = "0.0083", time_period = "Present", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{article_beck2023koppen}{amadeus} + \insertRef{article_beck2018present}{amadeus} } \author{ diff --git a/man/download_merra2.Rd b/man/download_merra2.Rd index 921bc93e..1ad8362d 100644 --- a/man/download_merra2.Rd +++ b/man/download_merra2.Rd @@ -52,110 +52,200 @@ The \code{download_merra2()} function accesses and downloads various meteorological and atmospheric collections from \href{https://gmao.gsfc.nasa.gov/reanalysis/MERRA-2/}{NASA's Modern-Era Retrospective analysis for Research and Applications, Version 2 (MERRA-2) model}. } \examples{ -\dontrun{ download_merra2( collection = "inst1_2d_int_Nx", - date = c("2024-01-01", "2024-01-05"), - directory_to_save = "./data", + date = c("2024-01-01", "2024-01-01"), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{data_gmao_merra-inst1_2d_asm_Nx}{amadeus} + \insertRef{data_gmao_merra-inst1_2d_int_Nx}{amadeus} + \insertRef{data_gmao_merra-inst1_2d_lfo_Nx}{amadeus} + \insertRef{data_gmao_merra-inst3_3d_asm_Np}{amadeus} + \insertRef{data_gmao_merra-inst3_3d_aer_Nv}{amadeus} + \insertRef{data_gmao_merra-inst3_3d_asm_Nv}{amadeus} + \insertRef{data_gmao_merra-inst3_3d_chm_Nv}{amadeus} + \insertRef{data_gmao_merra-inst3_3d_gas_Nv}{amadeus} + \insertRef{data_gmao_merra-inst3_2d_gas_Nx}{amadeus} + \insertRef{data_gmao_merra-inst6_3d_ana_Np}{amadeus} + \insertRef{data_gmao_merra-inst6_3d_ana_Nv}{amadeus} + \insertRef{data_gmao_merra-statD_2d_slv_Nx_m}{amadeus} + \insertRef{data_gmao_merra-statD_2d_slv_Nx_d}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_adg_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_aer_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_chm_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_csp_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_flx_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_int_Nx}{amadeus} + \insertRef{pawson_merra-2_2020}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_lnd_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_ocn_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_rad_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg1_2d_slv_Nx}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_mst_Ne}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_trb_Ne}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_nav_Ne}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_cld_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_mst_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_rad_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_tdt_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_trb_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_udt_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_odt_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_qdt_Np}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_asm_Nv}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_cld_Nv}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_mst_Nv}{amadeus} + \insertRef{data_gmao_merra-tavg3_3d_rad_Nv}{amadeus} + \insertRef{data_gmao_merra-tavg3_2d_glc_Nx}{amadeus} + \insertRef{data_gmao_merra-instM_2d_asm_Nx}{amadeus} + \insertRef{data_gmao_merra-instM_2d_int_Nx}{amadeus} + \insertRef{data_gmao_merra-instM_2d_lfo_Nx}{amadeus} + \insertRef{data_gmao_merra-instM_2d_gas_Nx}{amadeus} + \insertRef{data_gmao_merra-instM_3d_asm_Np}{amadeus} + \insertRef{data_gmao_merra-instM_3d_ana_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_adg_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_aer_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_chm_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_csp_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_flx_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_int_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_lfo_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_lnd_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_ocn_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_rad_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_slv_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_2d_glc_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_cld_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_mst_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_rad_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_tdt_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_trb_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_udt_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_odt_Np}{amadeus} + \insertRef{data_gmao_merra-tavgM_3d_qdt_Np}{amadeus} + \insertRef{data_gmao_merra-const_2d_asm_Nx}{amadeus} + \insertRef{data_gmao_merra-instU_2d_asm_Nx}{amadeus} + \insertRef{data_gmao_merra-instU_2d_int_Nx}{amadeus} + \insertRef{data_gmao_merra-instU_2d_lfo_Nx}{amadeus} + \insertRef{data_gmao_merra-instU_2d_gas_Nx}{amadeus} + \insertRef{data_gmao_merra-instU_3d_asm_Np}{amadeus} + \insertRef{data_gmao_merra-instU_3d_ana_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_adg_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_aer_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_chm_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_csp_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_flx_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_int_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_lfo_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_lnd_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_ocn_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_rad_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_slv_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_2d_glc_Nx}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_cld_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_mst_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_rad_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_tdt_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_trb_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_udt_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_odt_Np}{amadeus} + \insertRef{data_gmao_merra-tavgU_3d_qdt_Np}{amadeus} } \author{ diff --git a/man/download_modis.Rd b/man/download_modis.Rd index c32a306a..fd357915 100644 --- a/man/download_modis.Rd +++ b/man/download_modis.Rd @@ -31,7 +31,7 @@ One of \code{c("MOD09GA", "MOD11A1", "MOD06_L2", "MCD19A2", "MOD13A2", "VNP46A2" \code{c({start}, {end})}. Default is \code{c(3, 6)}.} \item{mod06_links}{character(1). CSV file path to MOD06_L2 download links -from NASA LPDAAC. Default is \code{NULL}.} +from \href{https://ladsweb.modaps.eosdis.nasa.gov/search/order/2/MOD06_L2--61}{NASA LAADS MOD06_L2}. Default is \code{NULL}.} \item{nasa_earth_data_token}{character(1). Token for downloading data from NASA. Should be set before @@ -70,55 +70,65 @@ Directory structure looks like input/modis/raw/\{version\}/\{product\}/\{year\}/\{day_of_year\}. } \examples{ -\dontrun{ -# example with MOD0GA product +# example with MOD09GA product download_modis( product = "MOD09GA", version = "61", - horizontal_tiles = c(8, 10), - vertical_tiles = c(4, 5), - date = c("2024-01-01", "2024-01-10"), - nasa_earth_data_token = readLines("~/pre_generated_token.txt"), - directory_to_save = "./data/mod09ga", + horizontal_tiles = c(8, 8), + vertical_tiles = c(4, 4), + date = c("2024-01-01", "2024-01-01"), + nasa_earth_data_token = + system.file("extdata", "nasa", "token.txt", package = "amadeus"), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) # example with MOD06_L2 product download_modis( product = "MOD06_L2", version = "61", - horizontal_tiles = c(8, 10), - vertical_tiles = c(4, 5), - mod06_links = "~/LAADS_query.2024-07-15T12_17.csv", - date = c("2024-01-01", "2024-01-10"), - nasa_earth_data_token = readLines("~/pre_generated_token.txt"), - directory_to_save = "./data/mod06l2", + horizontal_tiles = c(8, 8), + vertical_tiles = c(4, 4), + date = c("2024-01-01", "2024-01-01"), + mod06_links = + system.file( + "extdata", "nasa", "LAADS_query.2024-08-02T12_49.csv", + package = "amadeus" + ), + nasa_earth_data_token = + system.file("extdata", "nasa", "token.txt", package = "amadeus"), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) # example with VNP46A2 product download_modis( product = "VNP46A2", version = "61", - horizontal_tiles = c(8, 10), - vertical_tiles = c(4, 5), - date = c("2024-01-01", "2024-01-10"), - nasa_earth_data_token = readLines("~/pre_generated_token.txt"), - directory_to_save = "./data/vnp46a2", + horizontal_tiles = c(8, 8), + vertical_tiles = c(4, 4), + date = c("2024-01-01", "2024-01-01"), + nasa_earth_data_token = + system.file("extdata", "nasa", "token.txt", package = "amadeus"), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{data_mcd19a22021}{amadeus} + \insertRef{data_mod06l2_2017}{amadeus} + \insertRef{data_mod09ga2021}{amadeus} + \insertRef{data_mod11a12021}{amadeus} + \insertRef{data_mod13a22021}{amadeus} + \insertRef{article_roman2018vnp46}{amadeus} } \author{ diff --git a/man/download_narr.Rd b/man/download_narr.Rd index 7f8c4754..406d5224 100644 --- a/man/download_narr.Rd +++ b/man/download_narr.Rd @@ -45,17 +45,15 @@ The \code{download_narr} function accesses and downloads daily meteorological da "Pressure levels" variables contain variable values at 29 atmospheric levels, ranging from 1000 hPa to 100 hPa. All pressure levels data will be downloaded for each variable. } \examples{ -\dontrun{ download_narr( variables = c("weasd", "omega"), - year = c(2022, 2023), - directory_to_save = "./data", + year = c(2023, 2023), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{mesinger_north_2006}{amadeus} } diff --git a/man/download_nei.Rd b/man/download_nei.Rd index 358c3589..5f2e05ed 100644 --- a/man/download_nei.Rd +++ b/man/download_nei.Rd @@ -66,16 +66,15 @@ certificate updates in the future. } } \examples{ -\dontrun{ download_nei( year = c(2017L, 2020L), - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{web_usepa2024nei}{amadeus} } diff --git a/man/download_nlcd.Rd b/man/download_nlcd.Rd index db33662f..c63dd6fa 100644 --- a/man/download_nlcd.Rd +++ b/man/download_nlcd.Rd @@ -54,19 +54,18 @@ land cover data from the \href{https://www.mrlc.gov/data}{Multi-Resolution Land Characteristics (MRLC) Consortium's National Land Cover Database (NLCD) products data base}. } \examples{ -\dontrun{ download_nlcd( collection = "Coterminous United States", year = 2021, - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ -\insertRef{dewitz_national_2023}{amadeus} +\insertRef{dewitz_national_2023}{amadeus}\if{html}{\out{
}} \insertRef{dewitz_national_2024}{amadeus} } \author{ diff --git a/man/download_permit.Rd b/man/download_permit.Rd index 4f180700..32f288ee 100644 --- a/man/download_permit.Rd +++ b/man/download_permit.Rd @@ -10,6 +10,9 @@ download_permit(acknowledgement) \item{acknowledgement}{logical(1). Whether to start downloading} } +\value{ +NULL; returns a stop error if the acknowledgement is FALSE +} \description{ Return an error if the \code{acknowledgement = FALSE}. } diff --git a/man/download_prism.Rd b/man/download_prism.Rd index c00f6ca3..b3c51162 100644 --- a/man/download_prism.Rd +++ b/man/download_prism.Rd @@ -71,19 +71,17 @@ Accesses and downloads Oregon State University's PRISM data from the PRISM Climate Group Web Service } \examples{ -\dontrun{ download_prism( time = "202104", element = "ppt", data_type = "ts", format = "nc", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{article_daly2000prism}{amadeus} diff --git a/man/download_remove_command.Rd b/man/download_remove_command.Rd index b6cae4fa..249004c0 100644 --- a/man/download_remove_command.Rd +++ b/man/download_remove_command.Rd @@ -12,6 +12,9 @@ download_remove_command(commands_txt = NULL, remove = FALSE) \item{remove}{logical(1). Remove (\code{TRUE}) or keep (\code{FALSE}) commands} } +\value{ +NULL; removes .txt/.bat file storing all download commands. +} \description{ Remove or retain the .txt file storing all download commands. } diff --git a/man/download_remove_zips.Rd b/man/download_remove_zips.Rd index 72d26dbc..a3d5908b 100644 --- a/man/download_remove_zips.Rd +++ b/man/download_remove_zips.Rd @@ -11,6 +11,9 @@ download_remove_zips(remove = FALSE, download_name) \item{download_name}{character. Full zip file path} } +\value{ +NULL; removes downloaded zip files after they are unzipped +} \description{ Remove downloaded ".zip" files. } diff --git a/man/download_run.Rd b/man/download_run.Rd index 3c648fa4..03571100 100644 --- a/man/download_run.Rd +++ b/man/download_run.Rd @@ -4,14 +4,21 @@ \alias{download_run} \title{Run download commands} \usage{ -download_run(download = FALSE, system_command = NULL) +download_run(download = FALSE, commands_txt = NULL, remove = FALSE) } \arguments{ \item{download}{logical(1). Execute (\code{TRUE}) or skip (\code{FALSE}) download.} -\item{system_command}{character(1). Linux command to execute downloads. -Inherited from data download function.} +\item{commands_txt}{character(1). Path of download commands} + +\item{remove}{logical(1). Remove (\code{TRUE}) or +keep (\code{FALSE}) command. Passed to \code{download_remove_commands}.} +} +\value{ +NULL; runs download commands with shell (Unix/Linux) or +command prompt (Windows) and removes \code{commands_txt} file if +\code{remove = TRUE}. } \description{ Execute or skip the commands listed in the ...wget/curl_commands.txt file diff --git a/man/download_sedac_groads.Rd b/man/download_sedac_groads.Rd index 385800c0..21812a18 100644 --- a/man/download_sedac_groads.Rd +++ b/man/download_sedac_groads.Rd @@ -53,17 +53,16 @@ The \code{download_sedac_groads()} function accesses and downloads roads data from \href{https://sedac.ciesin.columbia.edu/data/set/groads-global-roads-open-access-v1/data-download}{NASA's Global Roads Open Access Data Set (gROADS), v1 (1980-2010)}. } \examples{ -\dontrun{ download_sedac_groads( data_region = "Americas", data_format = "Shapefile", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{data_ciesin2013groads}{amadeus} } diff --git a/man/download_sedac_population.Rd b/man/download_sedac_population.Rd index 4d0533b9..3cb7a8c9 100644 --- a/man/download_sedac_population.Rd +++ b/man/download_sedac_population.Rd @@ -57,18 +57,17 @@ The \code{download_sedac_population()} function accesses and downloads population density data from \href{https://sedac.ciesin.columbia.edu/data/set/gpw-v4-population-density-adjusted-to-2015-unwpp-country-totals-rev11}{NASA's UN WPP-Adjusted Population Density, v4.11}. } \examples{ -\dontrun{ download_sedac_population( data_resolution = "30 second", data_format = "GeoTIFF", year = "2020", - directory_to_save = "./data", + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, - remove_command = TRUE + download = FALSE, # NOTE: download skipped for examples, + remove_command = TRUE, + unzip = FALSE ) } -} \references{ \insertRef{data_ciesin2017gpwv4}{amadeus} } diff --git a/man/download_sink.Rd b/man/download_sink.Rd index 06dc401b..66a11cbe 100644 --- a/man/download_sink.Rd +++ b/man/download_sink.Rd @@ -9,6 +9,10 @@ download_sink(command_txt) \arguments{ \item{command_txt}{character(1). file path to export commands.} } +\value{ +NULL; creates and opens connection to text file to store +download commands +} \description{ Open connection to \code{command_txt} file to store download commands. } diff --git a/man/download_terraclimate.Rd b/man/download_terraclimate.Rd index bb52a181..4fff93f2 100644 --- a/man/download_terraclimate.Rd +++ b/man/download_terraclimate.Rd @@ -42,17 +42,15 @@ folder within \code{directory_to_save}. The \code{download_terraclimate} function accesses and downloads climate and water balance data from the \href{https://www.climatologylab.org/terraclimate.html}{University of California Merced Climatology Lab's TerraClimate dataset}. } \examples{ -\dontrun{ download_terraclimate( variables = "Precipitation", - year = c(2023, 2024), - directory_to_save = "./data", + year = c(2023, 2023), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{article_abatzoglou2018terraclimate}{amadeus} } diff --git a/man/download_tri.Rd b/man/download_tri.Rd index 4efdf85a..7df21f9d 100644 --- a/man/download_tri.Rd +++ b/man/download_tri.Rd @@ -36,16 +36,14 @@ NULL; Comma-separated value (CSV) files will be stored in The \code{download_tri()} function accesses and downloads toxic release data from the \href{https://www.epa.gov/toxics-release-inventory-tri-program/tri-data-action-0}{U.S. Environmental Protection Agency's (EPA) Toxic Release Inventory (TRI) Program}. } \examples{ -\dontrun{ download_tri( - year = c(2020L, 2021L), - directory_to_save = "./data", + year = c(2021L, 2021L), + directory_to_save = tempdir(), acknowledgement = TRUE, - download = TRUE, + download = FALSE, # NOTE: download skipped for examples, remove_command = TRUE ) } -} \references{ \insertRef{web_usepa2024tri}{amadeus} } diff --git a/man/download_unzip.Rd b/man/download_unzip.Rd index 4ce4c32c..8f787ca4 100644 --- a/man/download_unzip.Rd +++ b/man/download_unzip.Rd @@ -14,6 +14,9 @@ data} \item{unzip}{logical(1). Unzip (\code{TRUE}) or not.} } +\value{ +NULL; unzips downloaded zip files +} \description{ Unzip (inflate) downloaded ".zip" files. } diff --git a/man/process_covariates.Rd b/man/process_covariates.Rd index fd5f63b4..1c582555 100644 --- a/man/process_covariates.Rd +++ b/man/process_covariates.Rd @@ -35,11 +35,11 @@ data files before passing to \code{process_covariates}}. } \examples{ \dontrun{ -narr <- process_covariates( +process_covariates( covariate = "narr", - date = c("2023-01-01", "2023-01-10"), + date = c("2018-01-01", "2018-01-01"), variable = "weasd", - path = "./data/weasd" + path = system.file("extdata", "examples", "narr", "weasd") ) } } diff --git a/man/process_narr.Rd b/man/process_narr.Rd index fd674088..78685a37 100644 --- a/man/process_narr.Rd +++ b/man/process_narr.Rd @@ -40,10 +40,10 @@ pressure level, and date. } \examples{ \dontrun{ -narr <- process_narr( - date = c("2022-01-01", "2022-01-10"), +process_narr( + date = c("2018-01-01", "2018-01-01"), variable = "weasd", - path = "./data/weasd" + path = "./tests/testdata/narr/weasd" ) } } diff --git a/man/test_download_functions.Rd b/man/test_download_functions.Rd index 1431f1ba..362eae78 100644 --- a/man/test_download_functions.Rd +++ b/man/test_download_functions.Rd @@ -17,6 +17,9 @@ test_download_functions( \item{url_status}{logical vector for URL status = 200} } +\value{ +NULL; returns stop error if one or more tests fail +} \description{ Implement directory, file, and download URL unit tests. } diff --git a/tests/testthat/test-calculate_covariates.R b/tests/testthat/test-calculate_covariates.R index da955f12..dc9c69cf 100644 --- a/tests/testthat/test-calculate_covariates.R +++ b/tests/testthat/test-calculate_covariates.R @@ -1807,6 +1807,54 @@ testthat::test_that("calc_lagged returns as expected.", { } }) +## lagged variables with geometry +testthat::test_that("calc_lagged(geom = TRUE) works", { + withr::local_package("terra") + withr::local_package("data.table") + ncp <- data.frame(lon = -78.8277, lat = 35.95013) + ncp$site_id <- "3799900018810101" + # expect function + testthat::expect_true( + is.function(calc_lagged) + ) + narr <- process_narr( + date = c("2018-01-01", "2018-01-10"), + variable = "weasd", + path = + testthat::test_path( + "..", + "testdata", + "narr", + "weasd" + ) + ) + narr_covariate <- + calc_narr( + from = narr, + locs = ncp, + locs_id = "site_id", + radius = 0, + fun = "mean" + ) + # set column names + narr_covariate <- calc_setcolumns( + from = narr_covariate, + lag = 0, + dataset = "narr", + locs_id = "site_id" + ) + + # expect error with geom = TRUE and locs as data.frame + testthat::expect_error( + calc_lagged( + from = narr_covariate, + date = c("2018-01-02", "2018-01-04"), + lag = 1, + geom = TRUE + ) + ) +}) + ## 19. Wrapper #### testthat::test_that("calc_covariates wrapper works", { diff --git a/tests/testthat/test-download_functions.R b/tests/testthat/test-download_functions.R index cc12aaa8..1f3b55c4 100644 --- a/tests/testthat/test-download_functions.R +++ b/tests/testthat/test-download_functions.R @@ -35,71 +35,66 @@ testthat::test_that("Error when one parameter is NULL.", { } }) + testthat::test_that("Errors when temporal ranges invalid.", { - error_directory <- testthat::test_path("..", "testdata", "error_temp/") - expect_error( - download_geos( + withr::with_tempdir({ + expect_error( + download_geos( date = c("1900-01-01", "2018-01-01"), collection = "aqc_tavg_1hr_g1440x721_v1", acknowledgement = TRUE, - directory_to_save = error_directory - ) - ) - expect_error( - download_aqs( - year = c(1900, 2022), - acknowledgement = TRUE, - directory_to_save = error_directory + directory_to_save = "." + ) ) - ) - expect_error( - download_narr( + expect_error( + download_aqs( year = c(1900, 2022), - variables = "air.sfc", acknowledgement = TRUE, - directory_to_save = error_directory + directory_to_save = "." + ) ) - ) - expect_error( - download_merra2( - date = c("1900-01-01", "2023-09-01"), - collection = "inst1_2d_asm_Nx", - directory_to_save = error_directory, - acknowledgement = TRUE, - remove_command = TRUE + expect_error( + download_narr( + year = c(1900, 2022), + variables = "air.sfc", + acknowledgement = TRUE, + directory_to_save = "." + ) ) - ) - file.remove( - testthat::test_path( - "..", "testdata", "error_temp", - "merra2_1900-01-01_2023-09-01_wget_commands.txt" + expect_error( + download_merra2( + date = c("1900-01-01", "2023-09-01"), + collection = "inst1_2d_asm_Nx", + directory_to_save = ".", + acknowledgement = TRUE, + remove_command = TRUE + ) ) - ) - sink() - expect_error( - download_hms( - date = c("1900-01-01", "2018-01-01"), - directory_to_save = error_directory, - acknowledgement = TRUE + sink() + expect_error( + download_hms( + date = c("1900-01-01", "2018-01-01"), + directory_to_save = ".", + acknowledgement = TRUE + ) ) - ) - expect_error( - download_gridmet( - year = c(1900, 2022), - variables = "Precipitation", - acknowledgement = TRUE, - directory_to_save = error_directory + expect_error( + download_gridmet( + year = c(1900, 2022), + variables = "Precipitation", + acknowledgement = TRUE, + directory_to_save = "." + ) ) - ) - expect_error( - download_terraclimate( - year = c(1900, 2022), - variables = "Wind Speed", - acknowledgement = TRUE, - directory_to_save = error_directory + expect_error( + download_terraclimate( + year = c(1900, 2022), + variables = "Wind Speed", + acknowledgement = TRUE, + directory_to_save = ".", + ) ) - ) - unlink(error_directory, recursive = TRUE) + }) }) testthat::test_that("EPA AQS download URLs have HTTP status 200.", { @@ -110,7 +105,7 @@ testthat::test_that("EPA AQS download URLs have HTTP status 200.", { year_end <- 2022 resolution_temporal <- "daily" parameter_code <- 88101 - directory_to_save <- testthat::test_path("..", "testdata", "aqs_temp") + directory_to_save <- paste0(tempdir(), "/epa/") # run download function download_data(dataset_name = "aqs", year = c(year_start, year_end), @@ -150,7 +145,6 @@ testthat::test_that("EPA AQS download URLs have HTTP status 200.", { commands_path = commands_path, url_status = url_status) # remove file with commands after test - file.remove(commands_path) unlink(directory_to_save, recursive = TRUE) }) @@ -159,7 +153,7 @@ testthat::test_that("Ecoregion download URLs have HTTP status 200.", { withr::local_package("httr") withr::local_package("stringr") # function parameters - directory_to_save <- testthat::test_path("..", "testdata", "eco_temp") + directory_to_save <- paste0(tempdir(), "/eco/") certificate <- system.file("extdata/cacert_gaftp_epa.pem", package = "amadeus") # run download function @@ -216,6 +210,17 @@ testthat::test_that("Ecoregion download URLs have HTTP status 200.", { epa_certificate_path = certificate ) ) + testthat::expect_true( + dir.exists(paste0(directory_to_save, "/data_files")) + ) + testthat::expect_equal( + length( + list.files( + directory_to_save, recursive = TRUE, include.dirs = TRUE + ) + ), + 1 + ) unlink(directory_to_save, recursive = TRUE) }) @@ -228,8 +233,7 @@ testthat::test_that("GEOS-CF download URLs have HTTP status 200.", { date_end <- "2019-09-09" collections <- c("aqc_tavg_1hr_g1440x721_v1", "chm_inst_1hr_g1440x721_p23") - directory_to_save <- testthat::test_path("..", "testdata", "geos_temp/") - + directory_to_save <- paste0(tempdir(), "/geos/") # run download function testthat::expect_no_error( download_data(dataset_name = "geos", @@ -269,7 +273,7 @@ testthat::test_that("GMTED download URLs have HTTP status 200.", { statistics <- c("Breakline Emphasis", "Standard Deviation Statistic") resolution <- "7.5 arc-seconds" - directory_to_save <- testthat::test_path("..", "testdata", "gmted_temp") + directory_to_save <- paste0(tempdir(), "/gmted/") for (s in seq_along(statistics)) { # run download function download_data(dataset_name = "gmted", @@ -313,6 +317,11 @@ testthat::test_that("GMTED download URLs have HTTP status 200.", { file.path(filename), recursive = TRUE ) + file.create( + file.path( + paste0(directory_to_save, "/data_files/test.txt") + ) + ) # remove file with commands after test # remove temporary gmted testthat::expect_no_error( @@ -326,6 +335,17 @@ testthat::test_that("GMTED download URLs have HTTP status 200.", { remove_command = TRUE, download = FALSE) ) + testthat::expect_true( + dir.exists(paste0(directory_to_save, "/data_files")) + ) + testthat::expect_equal( + length( + list.files( + directory_to_save, recursive = TRUE, include.dirs = TRUE + ) + ), + 2 + ) unlink(directory_to_save, recursive = TRUE) } }) @@ -338,7 +358,7 @@ testthat::test_that("MERRA2 download URLs have HTTP status 200.", { date_start <- "2022-02-14" date_end <- "2022-03-08" collections <- c("inst1_2d_asm_Nx", "inst3_3d_asm_Np") - directory_to_save <- testthat::test_path("..", "testdata", "merra2_temp/") + directory_to_save <- paste0(tempdir(), "/merra2/") # run download function testthat::expect_no_error( download_data(dataset_name = "merra2", @@ -393,7 +413,7 @@ testthat::test_that("NARR download URLs have HTTP status 200.", { year_start <- 2018 year_end <- 2018 variables <- c("weasd", "omega", "soill") # includes monolevel, pressure level, subsurface - directory_to_save <- testthat::test_path("..", "testdata", "narr_temp/") + directory_to_save <- paste0(tempdir(), "/narr/") # run download function download_data(dataset_name = "narr", year = c(year_start, year_end), @@ -446,7 +466,7 @@ testthat::test_that("NOAA HMS Smoke download URLs have HTTP status 200.", { # function parameters date_start <- "2022-08-12" date_end <- "2022-09-21" - directory_to_save <- testthat::test_path("..", "testdata", "hms_temp") + directory_to_save <- paste0(tempdir(), "/hms/") data_formats <- c("Shapefile", "KML") for (d in seq_along(data_formats)) { # run download function @@ -497,7 +517,7 @@ testthat::test_that("NOAA HMS Smoke download URLs have HTTP status 200.", { }) testthat::test_that("download_hms error for unzip and directory.", { - error_directory <- testthat::test_path("..", "testdata", "error_temp/") + error_directory <- paste0(tempdir(), "/error/") testthat::expect_error( download_data( dataset_name = "hms", @@ -517,7 +537,7 @@ testthat::test_that("NLCD download URLs have HTTP status 200.", { years <- c(2021, 2019, 2016) collections <- c(rep("Coterminous United States", 2), "Alaska") collection_codes <- c(rep("l48", 2), "ak") - directory_to_save <- testthat::test_path("..", "testdata", "nlcd_temp") + directory_to_save <- paste0(tempdir(), "/nlcd/") # run download function for (y in seq_along(years)) { download_data(dataset_name = "nlcd", @@ -580,7 +600,7 @@ testthat::test_that("SEDAC groads download URLs have HTTP status 200.", { # function parameters data_regions <- c("Americas", "Global") data_formats <- c("Geodatabase", "Shapefile") - directory_to_save <- testthat::test_path("..", "testdata", "groad_temp") + directory_to_save <- paste0(tempdir(), "/groads/") # run download function for (r in seq_along(data_regions)) { data_region <- data_regions[r] @@ -647,7 +667,7 @@ testthat::test_that("SEDAC population download URLs have HTTP status 200.", { data_formats <- c("GeoTIFF", "ASCII") data_resolutions <- cbind(c("30 second"), c("30_sec")) - directory_to_save <- testthat::test_path("..", "testdata", "pop_temp") + directory_to_save <- paste0(tempdir(), "/pop/") for (f in seq_along(data_formats)) { data_format <- data_formats[f] for (y in seq_along(years)) { @@ -717,7 +737,7 @@ testthat::test_that("SEDAC population data types are coerced.", { year <- c("all") data_formats <- c("GeoTIFF", "ASCII", "netCDF") data_resolutions <- c("30 second", "2pt5_min") - directory_to_save <- testthat::test_path("..", "testdata", "pop_temp/") + directory_to_save <- paste0(tempdir(), "/pop/") for (f in seq_along(data_formats)) { download_data(dataset_name = "sedac_population", year = year, @@ -759,7 +779,7 @@ testthat::test_that("Koppen Geiger download URLs have HTTP status 200.", { # function parameters time_periods <- c("Present", "Future") data_resolutions <- c("0.0083") - directory_to_save <- testthat::test_path("..", "testdata", "kop_temp") + directory_to_save <- paste0(tempdir(), "/kop/") # run download function for (p in seq_along(time_periods)) { time_period <- time_periods[p] @@ -819,7 +839,7 @@ testthat::test_that("MODIS-MOD09GA download URLs have HTTP status 200.", { horizontal_tiles <- c(12, 13) vertical_tiles <- c(5, 6) nasa_earth_data_token <- "tOkEnPlAcEhOlDeR" - directory_to_save <- testthat::test_path("..", "testdata/", "") + directory_to_save <- paste0(tempdir(), "/mod/") for (y in seq_along(years)) { date_start <- paste0(years[y], "-06-20") date_end <- paste0(years[y], "-06-24") @@ -858,6 +878,7 @@ testthat::test_that("MODIS-MOD09GA download URLs have HTTP status 200.", { # remove file with commands after test file.remove(commands_path) } + unlink(directory_to_save, recursive = TRUE) }) @@ -872,7 +893,7 @@ testthat::test_that("MODIS-MOD06L2 download URLs have HTTP status 200.", { nasa_earth_data_token <- "tOkEnPlAcEhOlDeR" horizontal_tiles <- c(8, 10) vertical_tiles <- c(4, 5) - directory_to_save <- testthat::test_path("..", "testdata/", "") + directory_to_save <- paste0(tempdir(), "/mod/") testthat::expect_error( kax <- download_data(dataset_name = "modis", @@ -936,6 +957,7 @@ testthat::test_that("MODIS-MOD06L2 download URLs have HTTP status 200.", { url_status = url_status) # remove file with commands after test file.remove(commands_path) + unlink(directory_to_save, recursive = TRUE) }) @@ -950,7 +972,7 @@ testthat::test_that("MODIS download error cases.", { horizontal_tiles <- c(12, 13) vertical_tiles <- c(5, 6) nasa_earth_data_token <- "tOkEnPlAcEhOlDeR" - directory_to_save <- testthat::test_path("..", "testdata/", "") + directory_to_save <- paste0(tempdir(), "/mod/") date_start <- paste0(years, "-06-25") date_end <- paste0(years, "-06-28") @@ -1066,6 +1088,7 @@ testthat::test_that("MODIS download error cases.", { url_status = url_status) # remove file with commands after test file.remove(commands_path) + unlink(directory_to_save, recursive = TRUE) }) @@ -1073,7 +1096,7 @@ testthat::test_that("EPA TRI download URLs have HTTP status 200.", { withr::local_package("httr") withr::local_package("stringr") # function parameters - directory_to_save <- testthat::test_path("..", "testdata", "tri_temp/") + directory_to_save <- paste0(tempdir(), "/tri/") # run download function download_data(dataset_name = "tri", directory_to_save = directory_to_save, @@ -1113,7 +1136,7 @@ testthat::test_that("EPA NEI (AADT) download URLs have HTTP status 200.", { withr::local_package("httr") withr::local_package("stringr") # function parameters - directory_to_save <- testthat::test_path("..", "testdata", "nei_temp") + directory_to_save <- paste0(tempdir(), "/nei/") certificate <- system.file("extdata/cacert_gaftp_epa.pem", package = "amadeus") # run download function @@ -1166,7 +1189,7 @@ testthat::test_that("EPA NEI (AADT) download LIVE.", { withr::local_package("httr") withr::local_package("stringr") # function parameters - directory_to_save <- testthat::test_path("..", "testdata", "nei_live") + directory_to_save <- paste0(tempdir(), "/nei/") certificate <- system.file("extdata/cacert_gaftp_epa.pem", package = "amadeus") # run download function @@ -1200,7 +1223,7 @@ testthat::test_that("Test error cases in EPA gaftp sources 1", { withr::local_package("stringr") # function parameters tdir <- tempdir() - directory_to_save <- testthat::test_path("..", "testdata", "epa_temp/") + directory_to_save <- paste0(tempdir(), "/epa/") certificate <- file.path(tdir, "cacert_gaftp_epa.pem") # remove if there is a preexisting file if (file.exists(certificate)) { @@ -1240,7 +1263,7 @@ testthat::test_that("Test error cases in EPA gaftp sources 2", { withr::local_package("stringr") # function parameters tdir <- tempdir(check = TRUE) - directory_to_save <- testthat::test_path("..", "testdata", "epa_temp/") + directory_to_save <- paste0(tempdir(), "/epa/") certificate <- file.path(tdir, "cacert_gaftp_epa.pem") # remove if there is a preexisting file if (file.exists(certificate)) { @@ -1321,7 +1344,7 @@ testthat::test_that("check_urls returns NULL undefined size.", { testthat::test_that("download_hms LIVE run.", { # function parameters date <- "2018-01-01" - directory <- testthat::test_path("..", "testdata", "hms_live") + directory <- paste0(tempdir(), "/hms/") # run download function download_data( dataset_name = "hms", @@ -1352,8 +1375,7 @@ testthat::test_that("gridmet download URLs have HTTP status 200.", { year_start <- 2018 year_end <- 2023 variables <- "Precipitation" - directory_to_save <- - testthat::test_path("..", "testdata", "gridmet_temp/") + directory_to_save <- paste0(tempdir(), "/gridmet/") # run download function download_data(dataset_name = "gridmet", year = c(year_start, year_end), @@ -1388,8 +1410,7 @@ testthat::test_that("gridmet error with invalid years.", { variables = "Precipitation", year = c(10, 11), acknowledgement = TRUE, - directory_to_save = - testthat::test_path("..", "testdata", "gridmet", "tmp") + directory_to_save = paste0(tempdir(), "/g/") ) ) }) @@ -1401,8 +1422,7 @@ testthat::test_that("gridmet error with invalid variables", { variables = "temp", year = c(2018, 2018), acknowledgement = TRUE, - directory_to_save = - testthat::test_path("..", "testdata", "gridmet", "tmp") + directory_to_save = paste0(tempdir(), "/g/") ) ) }) @@ -1414,8 +1434,7 @@ testthat::test_that("terraclimate download URLs have HTTP status 200.", { year_start <- 2018 year_end <- 2023 variables <- "Precipitation" - directory_to_save <- - testthat::test_path("..", "testdata", "terraclimate_temp/") + directory_to_save <- paste0(tempdir(), "/terracclimate/") # run download function download_data(dataset_name = "terraclimate", year = c(year_start, year_end), @@ -1450,8 +1469,7 @@ testthat::test_that("terraclimate error with invalid years.", { variables = "Precipitation", year = c(10, 11), acknowledgement = TRUE, - directory_to_save = - testthat::test_path("..", "testdata", "terraclimate", "tmp") + directory_to_save = paste0(tempdir(), "/epa/") ) ) }) @@ -1463,13 +1481,9 @@ testthat::test_that("terraclimate error with invalid variables", { variables = "temp", year = c(2018, 2018), acknowledgement = TRUE, - directory_to_save = - testthat::test_path("..", "testdata", "terraclimate", "tmp") + directory_to_save = paste0(tempdir(), "/epa/") ) ) - file.remove( - testthat::test_path("..", "testdata", "terraclimate", "tmp") - ) }) @@ -1487,7 +1501,7 @@ testthat::test_that("download_cropscape generates correct download commands (GMU withr::local_package("stringr") # Set up test data year <- 2010 - directory_to_save <- testthat::test_path("..", "testdata", "cps_temp/") + directory_to_save <- paste0(tempdir(), "/cps/") # Call the function testthat::expect_no_error( @@ -1532,7 +1546,7 @@ test_that("download_cropscape generates correct download commands (USDA)", { withr::local_package("stringr") # Set up test data year <- 2010 - directory_to_save <- testthat::test_path("..", "testdata", "cps_temp/") + directory_to_save <- paste0(tempdir(), "/cps/") # Call the function testthat::expect_no_error( @@ -1585,7 +1599,7 @@ testthat::test_that("download_prism downloads the correct data files", { element <- sample(element, 1) data_type <- "ts" format <- "nc" - directory_to_save <- testthat::test_path("..", "testdata", "prism_temp/") + directory_to_save <- paste0(tempdir(), "/prism/") acknowledgement <- TRUE download <- FALSE remove_command <- FALSE @@ -1645,7 +1659,7 @@ testthat::test_that("download_prism downloads the correct data files", { element <- "soltotal" data_type <- "ts" format <- "nc" - directory_to_save <- testthat::test_path("..", "testdata", "prism_temp/") + directory_to_save <- paste0(tempdir(), "/prism/") acknowledgement <- TRUE download <- FALSE remove_command <- FALSE @@ -1671,7 +1685,7 @@ testthat::test_that("download_huc works", { withr::local_package("httr") - directory_to_save <- testthat::test_path("..", "testdata", "huc_temp/") + directory_to_save <- paste0(tempdir(), "/huc/") allregions <- c("Lower48", "Islands") alltypes <- c("Seamless", "OceanCatchment") @@ -1726,21 +1740,40 @@ testthat::test_that("download_huc works", testthat::test_that("download_sink test", { - testfile <- testthat::test_path("../testdata", "sink_test.txt") + dir <- paste0(tempdir(), "/sink/") + dir.create(dir, recursive = TRUE) + testfile <- paste0(dir, "sink_test.txt") file.create(testfile) testthat::expect_no_error( download_sink(testfile) ) sink() + Sys.sleep(1.5) file.remove(testfile) + unlink(dir, recursive = TRUE) }) testthat::test_that("download_remove_zips test", { - testfile <- - testthat::test_path("..", "testdata", "yellowstone/barren", "coyote.zip") - dir.create(dirname(testfile), recursive = TRUE) - file.create(testfile, recursive = TRUE) + dir <- paste0(tempdir(), "/yellowstone/") + testfile1 <- paste0(dir, "barren/coyote.zip") + dir.create(dirname(testfile1), recursive = TRUE) + file.create(testfile1, recursive = TRUE) + testfile2 <- paste0(dir, "retain/retain.txt") + dir.create(dirname(testfile2), recursive = TRUE) + file.create(testfile2, recursive = TRUE) testthat::expect_no_error( - download_remove_zips(remove = TRUE, testfile) + download_remove_zips(remove = TRUE, testfile1) + ) + # expect only the testfile1 directory to be removed + testthat::expect_equal( + length( + list.files( + dir, + recursive = TRUE, + include.dirs = TRUE + ) + ), + 2 ) + unlink(paste0(dir, "/yellowstone")) }) diff --git a/tests/testthat/test-download_olm.R b/tests/testthat/test-download_olm.R index 1e6e7d8f..b96a02d6 100644 --- a/tests/testthat/test-download_olm.R +++ b/tests/testthat/test-download_olm.R @@ -9,7 +9,7 @@ testthat::test_that( ) product <- "no2_s5p.l3.trop.tmwm" format <- "p50_p90_2km*.*tif" - directory_to_save <- testthat::test_path("..", "testdata", "olm_temp/") + directory_to_save <- paste0(tempdir(), "/olm") acknowledgement <- TRUE download <- FALSE @@ -26,7 +26,7 @@ testthat::test_that( commands_path <- paste0( directory_to_save, - "OLM_queried_", + "/OLM_queried_", product, "_", Sys.Date(), diff --git a/vignettes/workflow.Rmd b/vignettes/workflow.Rmd index 01e726a6..71b6ccb4 100644 --- a/vignettes/workflow.Rmd +++ b/vignettes/workflow.Rmd @@ -26,11 +26,12 @@ The examples will utilize air temperature at 2m height ("air.2m") data from the Download data for years 2021 and 2022 with `download_data`. ```{r, eval = FALSE} +dir <- tempdir() download_data( dataset_name = "narr", variable = "air.2m", year = c(2021, 2022), - directory_to_save = "./inst/extdata", + directory_to_save = dir, acknowledgement = TRUE, download = TRUE, remove_command = TRUE @@ -40,7 +41,7 @@ download_data( Check for the downloaded files. ```{r, eval = FALSE} -list.files("./inst/extdata/air.2m") +list.files(paste0(dir, "/air.2m")) ``` ```{r, echo = FALSE} cat('[1] "air.2m.2021.nc" "air.2m.2022.nc"\n') @@ -55,7 +56,7 @@ temp_process <- process_covariates( covariate = "narr", variable = "air.2m", date = c("2021-12-28", "2022-01-03"), - path = "./inst/extdata/air.2m" + path = paste0(dir, "/air.2m") ) ```