Skip to content

Commit

Permalink
Add graceful fail to phenocam
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyenni committed Jul 12, 2022
1 parent 3228c92 commit e9f6c74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ Suggests:
VignetteBuilder:
knitr
Encoding: UTF-8
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
9 changes: 8 additions & 1 deletion R/phenocam.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
phenocam <- function(level = "daily", path = get_default_data_path())
{
level <- tolower(level)

if (httr::http_error("http://phenocam.sr.unh.edu/data/archive/portal/ROI/portal_SH_1000_1day.csv")) {
message("Data source broken.")
return(NULL)

} else {

pheno <- read.csv(url("http://phenocam.sr.unh.edu/data/archive/portal/ROI/portal_SH_1000_1day.csv"),
skip = 22, header = TRUE, na.strings = c(""), stringsAsFactors = FALSE,
colClasses = c("Date", rep("integer", 3), "character",
Expand Down Expand Up @@ -59,4 +66,4 @@ phenocam <- function(level = "daily", path = get_default_data_path())
dplyr::arrange(.data$newmoonnumber)
}
return(pheno)
}
}}
4 changes: 4 additions & 0 deletions tests/testthat/test-11-phenocam.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
context("checks phenocam summary output")

portal_data_path <- tempdir()
source_test <- httr::http_error("http://phenocam.sr.unh.edu/data/archive/portal/ROI/portal_SH_1000_1day.csv")
daily_pheno <- phenocam("daily", path = portal_data_path)
monthly_pheno <- phenocam("monthly", path = portal_data_path)
newmoon_pheno <- phenocam("newmoon", path = portal_data_path)

test_that("Daily option returns 32 columns", {
skip_if(source_test)
expect_equal(NCOL(daily_pheno), 32)
expect_equal(colnames(daily_pheno),
c("date","year","doy","image_count","midday_filename","midday_r","midday_g","midday_b",
Expand All @@ -16,12 +18,14 @@ test_that("Daily option returns 32 columns", {
})

test_that("Monthly option returns 7 columns", {
skip_if(source_test)
expect_equal(NCOL(monthly_pheno), 7)
expect_equal(colnames(monthly_pheno), c("year","month","mean_image_count","midday_gcc","midday_rcc",
"gcc_mean","rcc_mean"))
})

test_that("Newmoon option returns 6 columns", {
skip_if(source_test)
expect_that(dim(newmoon_pheno)[2], equals(6))
expect_equal(colnames(newmoon_pheno), c("newmoonnumber","mean_image_count","midday_gcc","midday_rcc",
"gcc_mean","rcc_mean"))
Expand Down

0 comments on commit e9f6c74

Please sign in to comment.