Skip to content

Commit

Permalink
Merge pull request #37 from jimhester/readr-2.0.0
Browse files Browse the repository at this point in the history
Changes for readr 2.0.0
  • Loading branch information
Jorrit Poelen authored May 19, 2021
2 parents 13bdb1e + fbc01f9 commit 5d1a29e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions R/rglobi.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ has_neo4j_api <- function() {
# @param url points to csv resource
read_csv_online <- function(url, ...) {
if (has_api()) {
as.data.frame(suppressMessages(readr::read_csv(url)))
} else {
stop(paste("GloBI data services are not available at [", globi_api_url, "]. Are you connected to the internet?", sep = ""))
res <- suppressWarnings(suppressMessages(as.data.frame(readr::read_csv(url))))

# Drop rows with all NAs
res <- res[rowSums(is.na(res)) != ncol(res), ]

return(res)
}

stop(paste("GloBI data services are not available at [", globi_api_url, "]. Are you connected to the internet?", sep = ""))
}

#' Get Species Interaction from GloBI
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/util.R → tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ read_csv_caching = function(url, ...) {
}

read_csv_offline = function(url, ...) {
readr::read_csv(cached_filename(url))
res <- suppressWarnings(suppressMessages(as.data.frame(readr::read_csv(cached_filename(url), progress = FALSE))))

# Drop rows with all NAs
res <- res[rowSums(is.na(res)) != ncol(res), ]

res
}
2 changes: 0 additions & 2 deletions tests/testthat/test-globi.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
context("rglobi")

source('util.R')

test_that("default prey", {
predatorPrey <- get_prey_of(taxon = "Homo sapiens", read_csv = read_csv_offline)
expect_true(length(predatorPrey) > 0)
Expand Down

0 comments on commit 5d1a29e

Please sign in to comment.