Skip to content

Commit

Permalink
Merge pull request #53 from sebpardo/master
Browse files Browse the repository at this point in the history
Fix ebirdfreq, associated tests, and update deprecated testthat functions, closes #52
  • Loading branch information
sebpardo authored Mar 10, 2017
2 parents 46e70d9 + 92a4319 commit 6248ce6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rebird
Version: 0.3.3
Version: 0.3.4
Date: 2016-03-23
Title: R Client for the eBird Database of Bird Observations
Description: A programmatic client for the eBird database, including functions
Expand Down
18 changes: 7 additions & 11 deletions R/ebirdfreq.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#' "CA-BC-GV").
#' If querying hotspots then the unique identifier is a 6-digit
#' number prepended with an "L" (e.g. "L196159"). All these codes
#' can be found by looking at the URL in the Explore Data eBird
#' page (http://ebird.org//GuideMe?cmd=changeLocation).
#' can be found by looking at the URL in each respective
#' location/hotspot webpage (which are accessible through the
#' "Explore Data" tab).
#' @param startyear Starting year for query. Defaults to 1900.
#' @param endyear Ending year for query. Defaults to current year
#' specified by Sys.Date().
Expand Down Expand Up @@ -68,14 +69,10 @@ ebirdfreq <- function(loctype, loc, startyear = 1900,
stop("Not a valid location type")
}

args <- list(cmd = "getChart", displayType = "download",
getLocations = loctype, loctypename = loc,
bYear = startyear, eYear = endyear, bMonth = startmonth,
eMonth = endmonth)
# Rename the loctypename placeholder with loctype
names(args)[names(args) == "loctypename"] <- loctype

url <- "http://ebird.org/ebird/BarChart"
args <- list(r = loc, byr = startyear, eyr = endyear, bmo = startmonth,
emo = endmonth, fmt = "tsv")

url <- "http://ebird.org/ebird/barchartData"
ret <- GET(url, query = args, ...)
stop_for_status(ret)
asChar <- readBin(ret$content, "character")
Expand All @@ -101,4 +98,3 @@ ebirdfreq <- function(loctype, loc, startyear = 1900,
tbl_df(freq_long)
}
}

6 changes: 4 additions & 2 deletions tests/testthat/test-ebirdfreq.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ test_that("ebirdfreq fails correctly", {
expect_error(ebirdfreq("hotspots", "foo123"), "Invalid hotspot code")
expect_error(ebirdfreq("country"), "Not a valid location type")
expect_error(ebirdfreq("counties", "CA-BC-ZZ"), "Specified location doesn't exist")
expect_warning(ebirdfreq("hotspots", "L196159", 1901, 1902, long = FALSE), "No observations returned")
expect_error(ebirdfreq("hotspots", "L196159", 1901, 1902, long = FALSE), regexp = "^Internal Server Error \\(HTTP 500\\)\\.$")
# for some reason the following fails:
# expect_error(ebirdfreq("hotspots", "L196159", 1900, 1902, long = FALSE), "Internal Server Error (HTTP 500).")
expect_error(ebirdfreq("foo", "CA-BC-ZZ"), "Not a valid location type")
})

2 changes: 1 addition & 1 deletion tests/testthat/test-ebirdgeo.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ test_that("ebirdgeo works correctly", {
expect_is(egeo$howMany, "integer")
expect_is(ebirdgeo(lat = 42, lng = -76, max=10, provisional=TRUE, hotspot=TRUE), "data.frame")
expect_equal(nrow(ebirdgeo(lat = 42, lng = -76, max=10, provisional=TRUE, hotspot=TRUE)), 10)
expect_that(ebirdgeo(lat = 40, lng = -120, dist = 50), not(gives_warning()))
expect_silent(ebirdgeo(lat = 40, lng = -120, dist = 50))
expect_warning(ebirdgeo(lat = 30, lng = -120, dist = 100), "Distance supplied was >50km")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-ebirdhotspot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("ebirdhotspot works correctly", {
out <- ebirdhotspot('L99381', max=10, provisional=TRUE)
expect_is(out, "data.frame")
expect_is(out$comName, "character")
expect_that(ebirdhotspot('L99381'), not(gives_warning()))
expect_silent(ebirdhotspot('L99381'))

expect_warning(ebirdhotspot(locID = 'L99381', back = 40))
})
8 changes: 4 additions & 4 deletions tests/testthat/test-ebirdloc.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ test_that("ebirdloc works correctly", {

simpler <- ebirdloc('L99381', max = 1, simple = TRUE)
lesssimpler <- ebirdloc('L99381', max = 1, simple = FALSE)
expect_less_than(NCOL(simpler), 15)
expect_that(NCOL(simpler), not(is_less_than(8)))
expect_less_than(NCOL(lesssimpler), 30)
expect_that(NCOL(lesssimpler), not(is_less_than(10)))
expect_lt(NCOL(simpler), 15)
expect_gt(NCOL(simpler), 8)
expect_lt(NCOL(lesssimpler), 30)
expect_gt(NCOL(lesssimpler), 10)
})


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ebirdnotable.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_that("ebirdnotable works correctly", {
expect_equal(dim(simpler), c(40,11))
# expect_equal(dim(lesssimpler), c(40,24))

expect_more_than(
expect_gt(
system.time(ebirdnotable(lat=42, lng=-70, max = 10, sleep = 1))[[3]]
, 1)
})

0 comments on commit 6248ce6

Please sign in to comment.