From de0cbfb2a94105adf26ab0e71064307fb9210ebf Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Wed, 11 Sep 2024 14:20:51 +0800 Subject: [PATCH 1/4] Use {withr} to avoid complications with changing working directory. See --- DESCRIPTION | 3 ++- R/internal_functions.R | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) 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/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) + } +} From e393abf7c6a3cc6f285370832d51c66fa074e1a1 Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Wed, 11 Sep 2024 14:21:04 +0800 Subject: [PATCH 2/4] Update internal database of stations --- data-raw/fetch_isd-history.md | 97 ++++++++++++++++------------------ inst/extdata/isd_diff.rda | Bin 3237595 -> 3239278 bytes inst/extdata/isd_history.rda | Bin 531762 -> 532287 bytes 3 files changed, 47 insertions(+), 50 deletions(-) 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