Skip to content

Commit

Permalink
Modify behaviour for reformat_GSOD to be more specific about
Browse files Browse the repository at this point in the history
file_list
  • Loading branch information
adamhsparks committed Jun 20, 2020
1 parent 4fa3340 commit 8d40b42
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
17 changes: 13 additions & 4 deletions R/reformat_GSOD.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
#' up a parallel backend of your choice, \emph{e.g.},
#' \code{future::plan("multisession")}. See Examples for more.
#'
#' @param dsn User supplied file path to location of data files on local disk
#' for tidying.
#' @param file_list User supplied list of files of data on local disk for
#' tidying.
#' @param dsn User supplied full file path to location of data files on local
#' disk for tidying.
#' @param file_list User supplied list of file paths to individual files of data
#' on local disk for tidying. Ignored if \code{dsn} is set. Use if there are
#' other files in the \code{dsn} that you do not wish to reformat.
#'
#' @details
#'
#' If multiple stations are given, data are summarised for each year by station,
#' which include vapour pressure and relative humidity elements calculated from
#' existing data in \acronym{GSOD}. Else, a single station is tidied and a data
Expand Down Expand Up @@ -93,6 +95,13 @@ reformat_GSOD <- function(dsn = NULL, file_list = NULL) {
load(system.file("extdata", "isd_history.rda", package = "GSODR")) # nocov
setkeyv(isd_history, "STNID")

# If both dsn and file_path are set, emit message that only dsn is used
if (!is.null(dsn) & !is.null(file_list)) {
message("\nYou have specified both `file_list` and `dsn`.\n",
"Proceeding with using only the value from `dsn`.\n",
"See `?reformat_GSOD` if this behaviour was not expected.\n")
}

# If dsn !NULL, create a list of files to reformat
if (!is.null(dsn)) {
file_list <- list.files(path = dsn,
Expand Down
10 changes: 6 additions & 4 deletions man/reformat_GSOD.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion tests/testthat/test-reformat_GSOD.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ test_that("reformat_GSOD file_list parameter reformats data properly", {

# set up options for curl

url_base <- "https://www.ncei.noaa.gov/data/global-summary-of-the-day/access/1960/"
url_base <-
"https://www.ncei.noaa.gov/data/global-summary-of-the-day/access/1960/"
test_files <-
c("06600099999.csv", "06620099999.csv")
destinations <- file.path(tempdir(), test_files)
Expand Down Expand Up @@ -45,6 +46,11 @@ test_that("reformat_GSOD file_list parameter reformats data properly", {
expect_length(x, 44)
expect_is(x, "data.frame")

# Check that a message is emitted when both dsn and file_list are set --------
expect_message(reformat_GSOD(dsn = tempdir(),
file_list = file_list),
regexp = "\nYou have specified both `file_list` and `dsn`. *")

unlink(destinations)
})

Expand Down

0 comments on commit 8d40b42

Please sign in to comment.