diff --git a/R/rglobi.R b/R/rglobi.R index d4b5aad..c3bf55e 100644 --- a/R/rglobi.R +++ b/R/rglobi.R @@ -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 diff --git a/tests/testthat/util.R b/tests/testthat/helper.R similarity index 65% rename from tests/testthat/util.R rename to tests/testthat/helper.R index 38e3ff3..119858a 100644 --- a/tests/testthat/util.R +++ b/tests/testthat/helper.R @@ -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 } diff --git a/tests/testthat/test-globi.R b/tests/testthat/test-globi.R index 214c2ae..752fc23 100644 --- a/tests/testthat/test-globi.R +++ b/tests/testthat/test-globi.R @@ -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)