Skip to content

Commit

Permalink
Better fail (#36)
Browse files Browse the repository at this point in the history
* remove data extended PDO data source

* only a warning for failed responses

* bump version and news

* update cran comments

* update r versions
  • Loading branch information
boshek authored Jul 11, 2020
1 parent 5004b64 commit 4920eeb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: rsoi
Title: Import Various Northern and Southern Hemisphere Climate
Indices
Version: 0.5.2
Version: 0.5.3
Authors@R:
c(person(given = "Sam",
family = "Albers",
Expand Down Expand Up @@ -31,4 +31,4 @@ Suggests:
tibble
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# rsoi NEWS

## rsoi v0.5.3
* Remove Extended PDO because data is no longer available.
* Fail more gracefully with data source issues

## rsoi v0.5.2
* Adding PDO after rpdo maintainers requested we start importing. Thanks @eliocamp (#33)

Expand Down
38 changes: 18 additions & 20 deletions R/download-pdo.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#' \item Month: Month of record
#' \item Year: Year of record
#' \item PDO: Pacific Decadal Oscillation index
#' \item PDO_e: Extended PDO (NCEI PDO index)
#' }

#' @examples
Expand All @@ -33,7 +32,6 @@
#'
#' @references
#' Original PDO: \url{https://oceanview.pfeg.noaa.gov/erddap/info/cciea_OC_PDO/index.html}
#' Extended PDO: \url{https://www.ncdc.noaa.gov/teleconnections/pdo/}
download_pdo <- function(use_cache = FALSE, file = NULL) {
with_cache(use_cache = use_cache, file = file,
memoised = download_pdo_memoised,
Expand All @@ -58,30 +56,30 @@ download_pdo_unmemoised <- function() {
pdo$Date = as.Date(pdo$Date)

# pdo extended reconstruction
pdo_link = paste0("https://www.ncdc.noaa.gov/teleconnections/pdo/data.csv")

res = check_response(pdo_link)

pdo_e = read.table(res,
col.names = c("Date", "PDO_e"),
skip = 2,
sep = ",",
stringsAsFactors = FALSE)
pdo_e$Year = as.numeric(substr(pdo_e$Date, 1, 4))
pdo_e$Month = substr(pdo_e$Date, 5, 7)
pdo_e$Date = as.Date(paste0(pdo_e$Year, "-", pdo_e$Month, "-01"))

pdo <- merge(pdo[, c("Date", "PDO")],
pdo_e[, c("Date", "PDO_e")],
by = "Date",
all = TRUE)
# pdo_link = paste0("https://www.ncdc.noaa.gov/teleconnections/pdo/data.csv")
#
# res = check_response(pdo_link)
#
# pdo_e = read.table(res,
# col.names = c("Date", "PDO_e"),
# skip = 2,
# sep = ",",
# stringsAsFactors = FALSE)
# pdo_e$Year = as.numeric(substr(pdo_e$Date, 1, 4))
# pdo_e$Month = substr(pdo_e$Date, 5, 7)
# pdo_e$Date = as.Date(paste0(pdo_e$Year, "-", pdo_e$Month, "-01"))
#
# pdo <- merge(pdo[, c("Date", "PDO")],
# pdo_e[, c("Date", "PDO_e")],
# by = "Date",
# all = TRUE)

pdo$Year = as.numeric(substr(pdo$Date, 1, 4))

pdo$Month = abbr_month(pdo$Date)

class(pdo) <- c("tbl_df", "tbl", "data.frame")
pdo[, c("Year", "Month", "Date", "PDO", "PDO_e")]
pdo[, c("Year", "Month", "Date", "PDO")]
}

# Memoised function
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check_response <- function(link){
response <- curl::curl_fetch_memory(link)

if(!response$status_code == 200){
stop(paste0("Non successful http request. Target server returning a ", response$status_code, " error code"),
warning(paste0("Non successful http request. Target server returning a ", response$status_code, " error code"),
call. = FALSE)
}

Expand Down
17 changes: 9 additions & 8 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# rsoi NEWS

## rsoi v0.5.2
* Adding PDO after rpdo maintainers requested we start importing. Thanks @eliocamp (#33)
## rsoi v0.5.3
* Removed extended PDO data source
* Fail more gracefully with data source issues

## Test environments

* local Windows 10, R 3.6.3
* local Windows 10, R 4.0.2
* ubuntu, os x, R 3.6.3 (travis-ci)
* ubuntu 16.04 (on github actions), R 3.6, R 3.5, R 3.4, R 3.3
* Windows Server 2019 (on github actions), R 3.6.3
* macOS Catalina 10.15 (on github actions), R 3.6.3
* ubuntu 16.04 (on github actions), 4.0.2, R 3.5, R 3.4, R 3.3
* Windows Server 2019 (on github actions), R 4.0.2
* macOS Catalina 10.15 (on github actions), R 4.0.2
* win-builder (devel and release)
* Windows, R 3.6.3 (on appveyor)
* Windows, R 4.0.2 (on appveyor)

## R CMD check results

There were no ERRORs or WARNINGs.
There were no ERRORs or WARNINGs. This fixes the error currently happening on CRAN right now.

## Downstream dependencies

Expand Down
2 changes: 0 additions & 2 deletions man/download_pdo.Rd

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

2 changes: 1 addition & 1 deletion man/rsoi-package.Rd

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

0 comments on commit 4920eeb

Please sign in to comment.