diff --git a/DESCRIPTION b/DESCRIPTION index 3727ff0b..e1f0d235 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,7 +53,8 @@ Imports: data.table (>= 1.15.4), R.utils, stats, - utils + utils, + withr Suggests: bit64, dplyr, diff --git a/NEWS.md b/NEWS.md index 7f1c7a0d..93930b3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ - Enforce {data.table} >= 1.15.4 due to issue with `fifelse()` as reported in +- Fix issue with working directory changing as reported in + # GSODR 4.1.1 ## Bug fixes diff --git a/R/internal_functions.R b/R/internal_functions.R index d799b18d..0eac65d4 100644 --- a/R/internal_functions.R +++ b/R/internal_functions.R @@ -199,13 +199,8 @@ # create a list of files that have been downloaded and untar them tar_files <- list.files(tempdir(), pattern = "*\\.tar.gz$", full.names = TRUE) - for (i in tar_files) { - wd <- getwd() - on.exit(setwd(wd)) - setwd(tempdir()) - year_dir <- substr(i, nchar(i) - 10, nchar(i) - 7) - utils::untar(i, exdir = year_dir) - } + + withr::with_dir(tempdir(), .untar_files(tar_files)) GSOD_list <- list.files( @@ -367,3 +362,19 @@ )[[1]] )) } + + +#' Untar GSOD Tar Archive Files +#' +#' @param tar_files a list of tar files located in in `tempdir()` +#' +#' @noRd +#' @return called for it's side-effects, untars the archive files in the +#' `tempdir()` + +.untar_files <- function(tar_files) { + for (i in tar_files) { + year_dir <- substr(i, nchar(i) - 10, nchar(i) - 7) + utils::untar(i, exdir = year_dir) + } +} diff --git a/codemeta.json b/codemeta.json index d0051159..29c14b6e 100644 --- a/codemeta.json +++ b/codemeta.json @@ -317,12 +317,24 @@ "identifier": "utils", "name": "utils" }, + "8": { + "@type": "SoftwareApplication", + "identifier": "withr", + "name": "withr", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=withr" + }, "SystemRequirements": null }, "applicationCategory": "Tools", "isPartOf": "https://ropensci.org", "keywords": ["US-NCEI", "meteorological-data", "global-weather", "weather", "weather-data", "meteorology", "station-data", "surface-weather", "data-access", "US-NCDC", "r", "gsod", "ncdc", "weather-stations", "global-data", "ncei", "weather-information", "historical-weather", "historical-data", "daily-data", "daily-weather", "rstats", "r-package"], - "fileSize": "4344.975KB", + "fileSize": "4347.54KB", "citation": [ { "@type": "SoftwareSourceCode", diff --git a/data-raw/fetch_isd-history.md b/data-raw/fetch_isd-history.md index 995a18e5..8b76963f 100644 --- a/data-raw/fetch_isd-history.md +++ b/data-raw/fetch_isd-history.md @@ -1,7 +1,7 @@ Fetch and Clean ‘isd_history.csv’ File ================ Adam H. Sparks -2024-07-21 +2024-09-11