Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use {withr} to avoid complications with changing working directory. #125

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.