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

Report removal, hotfix for CRAN #22

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: eia
Title: API Wrapper for 'US Energy Information Administration' Open Data
Version: 0.4.1
Version: 0.4.2
Authors@R:
c(person(
given = "Matthew",
Expand Down Expand Up @@ -28,10 +28,8 @@ Imports:
tibble,
httr,
jsonlite,
purrr,
memoise,
lubridate,
readxl
lubridate
Suggests:
testthat (>= 3.0.0),
knitr,
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ export(eia_dir)
export(eia_facets)
export(eia_get_key)
export(eia_metadata)
export(eia_report)
export(eia_set_key)
export(eiadate_to_date)
export(eiadate_to_date_seq)
export(report_drilling_productivity)
importFrom(httr,GET)
importFrom(httr,content)
importFrom(httr,write_disk)
importFrom(tibble,tibble)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# eia 0.4.2

* Removed one-off, non-API, report download function that no longer works but also do not intend to support within the scope of the package.
* Removed related. no longer needed package imports.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want a comma after the word "related"?

* Updated documentation.

# eia 0.4.1

* Re-factor of `eia_data()`:
Expand Down
120 changes: 60 additions & 60 deletions R/reports.R
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
#' Download data for various EIA reports
#'
#' These functions download data for various EIA reports found on the EIA
#' website but not necessarily available through the EIA API.
#'
#' The wrapper function and the individual report functions do not make API
#' calls and do not require an API key.
#'
#' @param id character, the report ID. See examples for available reports.
#' @param ... arguments passed to individual report data functions.
#'
#' @return a list, typically a list of data frames
#' @export
#'
#' @examples
#' \dontrun{
#' x <- eia_report("drilling productivity")
#' }
eia_report <- function(id, ...){
f <- switch(
id,
"drilling productivity" = report_drilling_productivity
)
f(...)
}
# #' Download data for various EIA reports
# #'
# #' These functions download data for various EIA reports found on the EIA
# #' website but not necessarily available through the EIA API.
# #'
# #' The wrapper function and the individual report functions do not make API
# #' calls and do not require an API key.
# #'
# #' @param id character, the report ID. See examples for available reports.
# #' @param ... arguments passed to individual report data functions.
# #'
# #' @return a list, typically a list of data frames
# #' @export
# #'
# #' @examples
# #' \dontrun{
# #' x <- eia_report("drilling productivity")
# #' }
# eia_report <- function(id, ...){
# f <- switch(
# id,
# "drilling productivity" = report_drilling_productivity
# )
# f(...)
# }

#' @importFrom httr GET write_disk
#' @export
#' @rdname eia_report
report_drilling_productivity <- function(){
url <- paste0("https://www.eia.gov/petroleum/drilling/xls/dpr-data.xlsx")
file <- file.path(tempdir(), "dpr-data.xlsx")
x <- httr::RETRY(verb = "GET", url = url, httr::write_disk(file))
x <- tryCatch(
purrr::map(1:7, ~{
z <- names(readxl::read_xlsx(file, .x, skip = 0, .name_repair = "minimal"))
z <- z[z != ""][-1]
x <- readxl::read_xlsx(file, .x, skip = 1, .name_repair = "minimal")
dplyr::bind_rows(x[1:5], x[c(1:2, 6:8)]) |>
dplyr::mutate(Fuel = factor(rep(z, each = nrow(x)), levels = z)) |>
dplyr::select(c(6, 1:5))
}),
error = function(e) NULL
)
y <- tryCatch(
readxl::read_xlsx(file, 8, .name_repair = "minimal"),
error = function(e) NULL
)
if(is.null(x)){
unlink(file, recursive = TRUE, force = TRUE)
message("Report not found.")
return(invisible())
}
names(x) <- readxl::excel_sheets(file)[1:7]
unlink(file, recursive = TRUE, force = TRUE)
list(
data = dplyr::bind_rows(x, .id = "Region") |>
dplyr::mutate(Region = factor(.data[["Region"]])),
counties = y
)
}
# #' @importFrom httr GET write_disk
# #' @export
# #' @rdname eia_report
# report_drilling_productivity <- function(){
# url <- paste0("https://www.eia.gov/petroleum/drilling/xls/dpr-data.xlsx")
# file <- file.path(tempdir(), "dpr-data.xlsx")
# x <- httr::RETRY(verb = "GET", url = url, httr::write_disk(file))
# x <- tryCatch(
# purrr::map(1:7, ~{
# z <- names(readxl::read_xlsx(file, .x, skip = 0, .name_repair = "minimal"))
# z <- z[z != ""][-1]
# x <- readxl::read_xlsx(file, .x, skip = 1, .name_repair = "minimal")
# dplyr::bind_rows(x[1:5], x[c(1:2, 6:8)]) |>
# dplyr::mutate(Fuel = factor(rep(z, each = nrow(x)), levels = z)) |>
# dplyr::select(c(6, 1:5))
# }),
# error = function(e) NULL
# )
# y <- tryCatch(
# readxl::read_xlsx(file, 8, .name_repair = "minimal"),
# error = function(e) NULL
# )
# if(is.null(x)){
# unlink(file, recursive = TRUE, force = TRUE)
# message("Report not found.")
# return(invisible())
# }
# names(x) <- readxl::excel_sheets(file)[1:7]
# unlink(file, recursive = TRUE, force = TRUE)
# list(
# data = dplyr::bind_rows(x, .id = "Region") |>
# dplyr::mutate(Region = factor(.data[["Region"]])),
# counties = y
# )
# }
32 changes: 4 additions & 28 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"codeRepository": "https://github.com/ropensci/eia",
"issueTracker": "https://github.com/ropensci/eia/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.4.1",
"version": "0.4.2",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.3.1 (2023-06-16)",
"runtimePlatform": "R version 4.3.1 (2023-06-16 ucrt)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -180,18 +180,6 @@
"sameAs": "https://CRAN.R-project.org/package=jsonlite"
},
"4": {
"@type": "SoftwareApplication",
"identifier": "purrr",
"name": "purrr",
"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=purrr"
},
"5": {
"@type": "SoftwareApplication",
"identifier": "memoise",
"name": "memoise",
Expand All @@ -203,7 +191,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=memoise"
},
"6": {
"5": {
"@type": "SoftwareApplication",
"identifier": "lubridate",
"name": "lubridate",
Expand All @@ -215,19 +203,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=lubridate"
},
"7": {
"@type": "SoftwareApplication",
"identifier": "readxl",
"name": "readxl",
"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=readxl"
},
"SystemRequirements": null
},
"fileSize": "202.642KB"
"fileSize": "205.522KB"
}
4 changes: 2 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
## Test environments

* Local Windows 10 install: R 4.3.1
* Local Windows 10 install: R 4.3.3
* Win Builder: R-devel, R-release
* Windows latest: R-release
* Ubuntu latest: R-devel, R-release, R-oldrel
* MacOS latest: R-release

## Update release

* Code updates and additional unit testing.
* Fix failing functionality as requested by CRAN.

## R CMD check results

Expand Down
32 changes: 0 additions & 32 deletions man/eia_report.Rd

This file was deleted.

23 changes: 12 additions & 11 deletions tests/testthat/test-reports.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
test_that("eia_report returns as expected", {
x <- eia_report(id = "drilling productivity")
expect_type(x, "list")
expect_equal(length(x), 2)
expect_equal(names(x), c("data", "counties"))
v <- c("Region", "Fuel", "Month", "Rig count", "Production per rig",
"Legacy production change", "Total production")
expect_equal(names(x$data), v)
v <- c("State", "County", "StateID", "CountyID", "Region")
expect_equal(names(x$counties), v)
})
# test_that("eia_report returns as expected", {
# skip_on_cran()
# x <- eia_report(id = "drilling productivity")
# expect_type(x, "list")
# expect_equal(length(x), 2)
# expect_equal(names(x), c("data", "counties"))
# v <- c("Region", "Fuel", "Month", "Rig count", "Production per rig",
# "Legacy production change", "Total production")
# expect_equal(names(x$data), v)
# v <- c("State", "County", "StateID", "CountyID", "Region")
# expect_equal(names(x$counties), v)
# })
Loading