Skip to content

Commit 93bb1f9

Browse files
authored
remove geometry column when geometry = FALSE (#80)
* remove geometry column when geometry = FALSE * remove st_drop_geometry * bug fix version
1 parent c8664b4 commit 93bb1f9

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: codec
22
Title: Community Data Explorer for Cincinnati
3-
Version: 0.7.0
3+
Version: 0.7.1
44
Authors@R: c(
55
person("Cole", "Brokamp",
66
email = "[email protected]",

R/codec_tdr.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ codec_data <- function(name, geography = cincy::tract_tigris_2010, geometry = FA
8484
d_sf <- dplyr::left_join(d, cincy::tract_tigris_2010, by = "census_tract_id_2010")
8585
d_sf <- sf::st_as_sf(d_sf)
8686
d_int <- cincy::interpolate(from = d_sf, to = geography, weights = "pop")
87-
if (!geometry) d_int <- sf::st_drop_geometry(tibble::as_tibble(d_int))
87+
if (!geometry) {
88+
d_int <- tibble::as_tibble(d_int) |>
89+
dplyr::select(-geometry)
90+
}
8891
d <- d_int
8992
}
9093

tests/testthat/test-codec_tdr.R

+13
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ test_that("codec_data works", {
1212
test_that("codec_data works with interpolation", {
1313
skip_if_no_cincy()
1414

15+
# geometry = TRUE
1516
codec_d <- codec_data("hamilton_landcover",
1617
geography = cincy::zcta_tigris_2010,
1718
geometry = TRUE)
1819
expect_equal(nrow(codec_d), 57)
20+
expect_equal(ncol(codec_d), 7)
1921
expect_identical(glimpse_attr(codec_d)$value[[2]], "hamilton_landcover")
2022
expect_s3_class(codec_d, "sf")
2123

24+
# geometry = FALSE
25+
codec_d <- codec_data("hamilton_landcover",
26+
geography = cincy::zcta_tigris_2010,
27+
geometry = FALSE)
28+
29+
expect_equal(nrow(codec_d), 57)
30+
expect_equal(ncol(codec_d), 6)
31+
expect_identical(glimpse_attr(codec_d)$value[[2]], "hamilton_landcover")
32+
expect_error(expect_s3_class(codec_d, "sf"))
2233
})
34+
35+

0 commit comments

Comments
 (0)