Skip to content

Commit

Permalink
Use {withr} to avoid complications with changing working directory. (#…
Browse files Browse the repository at this point in the history
…125)

* Use {withr} to avoid complications with changing working directory. See <#124>

* Update internal database of stations

* Update NEWS with bug fixes

* Update codemeta.json
  • Loading branch information
adamhsparks authored Sep 11, 2024
1 parent 8f55295 commit 0a80608
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 59 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Imports:
data.table (>= 1.15.4),
R.utils,
stats,
utils
utils,
withr
Suggests:
bit64,
dplyr,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Enforce {data.table} >= 1.15.4 due to issue with `fifelse()` as reported in <https://github.com/ropensci/GSODR/issues/121>

- Fix issue with working directory changing as reported in <https://github.com/ropensci/GSODR/issues/124#issuecomment-2342686025>

# GSODR 4.1.1

## Bug fixes
Expand Down
25 changes: 18 additions & 7 deletions R/internal_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
}
14 changes: 13 additions & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
97 changes: 47 additions & 50 deletions data-raw/fetch_isd-history.md

Large diffs are not rendered by default.

Binary file modified inst/extdata/isd_diff.rda
Binary file not shown.
Binary file modified inst/extdata/isd_history.rda
Binary file not shown.

0 comments on commit 0a80608

Please sign in to comment.