From 66e954abfa24f1f94392360b2d9df6b37e89b9a9 Mon Sep 17 00:00:00 2001 From: David Blodgett Date: Mon, 9 Oct 2023 15:47:59 -0500 Subject: [PATCH] remove web responses with 0 rows - fixes #361 --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ R/geoserver_tools.R | 5 +++++ tests/testthat/test_02_subset_extras.R | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 535c225d..0597cb3a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: nhdplusTools Type: Package Title: NHDPlus Tools -Version: 1.0.0 +Version: 1.0.1 Authors@R: c(person(given = "David", family = "Blodgett", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 80c3ef1f..8b58e39a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +nhdplusTools 1.0.1 +========== + +- fixed bug with large nhdplus downloads with empty tiles. #361 + nhdplusTools 1.0.0 ========== diff --git a/R/geoserver_tools.R b/R/geoserver_tools.R index 97594169..8e3c5f06 100644 --- a/R/geoserver_tools.R +++ b/R/geoserver_tools.R @@ -227,6 +227,11 @@ unify_types <- function(out) { } } } + + rows <- sapply(out, nrow) + + out <- out[rows > 0] + out } diff --git a/tests/testthat/test_02_subset_extras.R b/tests/testthat/test_02_subset_extras.R index 6d6fae98..4453c434 100644 --- a/tests/testthat/test_02_subset_extras.R +++ b/tests/testthat/test_02_subset_extras.R @@ -170,3 +170,14 @@ test_that("extras", { expect_equal(nhdplusTools:::get_empty("MULTIPOINT"), sf::st_multipoint()) expect_error(nhdplusTools:::get_empty("BORKED"), "unexpected geometry type") }) + +test_that("unify_types", { + + check <- list(data.frame(), data.frame(one = 1, two = "2"), data.frame(one = "1", two = 2)) + + out <- nhdplusTools:::unify_types(check) + + expect_equal(out, + list(structure(list(one = 1, two = 2), row.names = c(NA, -1L), class = "data.frame"), + structure(list(one = 1, two = 2), row.names = c(NA, -1L), class = "data.frame"))) +})