Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/ropensci/eia into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
leonawicz committed Oct 30, 2023
2 parents 81d78d2 + 4bec6c0 commit 7058633
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ eia_data <- function(dir, data = NULL, facets = NULL,

.freq_specs <- function(freq){
if (!is.character(freq) | length(freq) > 1)
stop("frequency must be a character value of length 1.")
stop("'freq' must be a character value of length 1.")
freqs <- c("annual", "yearly", "quarterly", "monthly", "daily", "hourly")
if (!freq %in% freqs)
stop("frequency must be one of: 'yearly', 'monthly', 'daily', or 'hourly'.")
stop("'freq' must be one of: 'annual', 'yearly', 'monthly', 'daily', or 'hourly'.")
paste0("&frequency=", freq)
}

Expand Down
2 changes: 1 addition & 1 deletion R/directory.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ eia_dir <- function(dir = NULL, tidy = TRUE, cache = TRUE, key = eia_get_key()){
} else {
message(paste0(
"No further sub-directories to discover.\n",
'Use `eia_metadata("', dir, '")` to explore this data.'
"Use `eia_metadata(', dir, ')` to explore this data."
))
}
if(tidy && is.data.frame(r))
Expand Down
19 changes: 16 additions & 3 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,29 @@ test_that("data queries return as expected", {
# Test no data
expect_error(suppressMessages(eia_data("electricity/zzz")), "Page not found")

# Test "freq" input value
err <- "'freq' must be one of: 'annual', 'yearly', 'monthly', 'daily', or 'hourly'."
expect_error(eia_data("electricity/retail-sales", freq = "anual"), err)
err <- "'freq' must be a character value of length 1."
expect_error(eia_data("electricity/retail-sales", freq = c("annual", "monthly")), err)

# Test non-character "start" input value
err <- "'start' must be a character matching the required frequency format."
expect_error(eia_data("electricity/retail-sales", freq = "annual", start = 2010), err)

# Test non-character "start" input value
# Test non-character "end" input value
err <- "'end' must be a character matching the required frequency format."
expect_error(eia_data("electricity/retail-sales", freq = "annual", end = 2010), err)

# Test non-numeric "length" input value
# Test "length" input value
x <- eia_data("electricity/retail-sales", length = 10)
expect_equal(nrow(x), 10)
err <- "'length' must be a single numeric value between 0 and 5000."
expect_error(eia_data("electricity/retail-sales", length = "10"), err)

# Test non-numeric offset input value
# Test "offset" input value
x <- eia_data("electricity/retail-sales", length = 10, offset = 10)
expect_equal(nrow(x), 10)
err <- "'offset' must be a single numeric value greater than 0."
expect_error(eia_data("electricity/retail-sales", offset = "10"), err)

Expand Down Expand Up @@ -123,6 +133,9 @@ test_that("metadata helper returns as expected", {
expect_type(x, "list")
expect_length(x, 3)

x <- eia_metadata("electricity/retail-sales", tidy = NA, cache = FALSE)
expect_type(x, "character")

})

options(eia_antidos = 1)
7 changes: 7 additions & 0 deletions tests/testthat/test-dirs.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ test_that("directory functions returns as expected", {
x <- eia_dir("electricity")
expect_s3_class(x, "tbl_df")
expect_equal(dim(x), c(6, 3))

msg <- paste0(
"No further sub-directories to discover.\n",
"Use `eia_metadata('electricity/retail-sales')` to explore this data."
)
expect_message(eia_dir("electricity/retail-sales"), msg)

})

options(eia_antidos = 1)

0 comments on commit 7058633

Please sign in to comment.