ccsarapas / lighthouse

Utility Functions for Lighthouse Institute Projects
https://ccsarapas.github.io/lighthouse/
Other
0 stars 0 forks source link

`summary_table()` and `summary_report()` fail if passed `sf` object #29

Open ccsarapas opened 2 weeks ago

ccsarapas commented 2 weeks ago

Reprex:

library(lighthouse)

nc <- st_read(system.file("shape/nc.shp", package = "sf"))

summary_table(nc, mean, .vars = BIR74)
# Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) :
#   no simple features geometry column present
# In addition: Warning message:
# Expected 2 pieces. Missing pieces filled with `NA` in 1 rows [2].

Works fine if coerced to data.frame or tibble:

summary_table(as.data.frame(nc), mean, .vars = BIR74)
# # A tibble: 1 × 2
#   Variable  mean
#   <chr>    <dbl>
# 1 BIR74    3300.

summary_table(tibble::as_tibble(nc), mean, .vars = BIR74)
# # A tibble: 1 × 2
#   Variable  mean
#   <chr>    <dbl>
# 1 BIR74    3300.
ccsarapas commented 1 week ago

Similar error for summary_report():

summary_report(nc, BIR74)
# Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) : 
#   no simple features geometry column present
# In addition: Warning message:
# Expected 2 pieces. Missing pieces filled with `NA` in 1 rows [3].