walkerke / tidycensus

Load US Census boundary and attribute data as 'tidyverse' and 'sf'-ready data frames in R
https://walker-data.com/tidycensus
Other
639 stars 100 forks source link

2014 ACS 5-year data breaking in get_acs call #501

Closed seandalby closed 1 year ago

seandalby commented 1 year ago

Hi,

The code below works, but it breaks if you put the year 2014 in the loop. We get "Error in CPL_get_z_range(obj, 3) : z-error: expecting 3 columns" - is this something wrong with the geometry provided by census or within the function? Not sure if this happens with states other than PA but it might.

for (y in c(2009:2013,2015:2021)){

pa_acs_tr_y <- get_acs(geography = "tract", variables = "B19013_001E", state = "PA", geometry = TRUE, year = y) %>% rename( med_hh_inc = estimate, med_hh_inc_moe = moe ) %>% dplyr::select(GEOID, med_hh_inc, med_hh_inc_moe, geometry) %>% mutate(year = y)

if(y == 2009){pa_acs_tr <- pa_acs_tr_y} else{pa_acs_tr <- rbind(pa_acs_tr, pa_acs_tr_y)} }

walkerke commented 1 year ago

I can't reproduce this error. Could you do three things for me?

  1. Make sure your tidycensus, tigris, and sf packages are fully up to date;
  2. Call library(sf) and let me know what the printed message says;
  3. Share the results of your sessionInfo() here.
seandalby commented 1 year ago

No problem - also FYI I'm working on a mac w/M1 chip

  1. Just reinstalled packages, so we're good there
  2. "Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE" is the printed message
  3. Here's my session info (enclosed in the *'s):

R version 4.2.2 Patched (2022-11-23 r83383) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Ventura 13.1

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] sf_1.0-9

loaded via a namespace (and not attached): [1] Rcpp_1.0.9 rstudioapi_0.14 knitr_1.41 magrittr_2.0.3 units_0.8-0 tidyselect_1.1.2 R6_2.5.1
[8] rlang_1.0.4 fastmap_1.1.0 fansi_1.0.3 dplyr_1.0.9 tools_4.2.2 grid_4.2.2 data.table_1.14.6 [15] xfun_0.35 KernSmooth_2.23-20 utf8_1.2.2 e1071_1.7-11 cli_3.3.0 DBI_1.1.3 dbplyr_2.2.1
[22] class_7.3-20 htmltools_0.5.4 assertthat_0.2.1 digest_0.6.29 tibble_3.1.8 lifecycle_1.0.1 purrr_0.3.4
[29] htmlwidgets_1.5.4 vctrs_0.4.1 glue_1.6.2 proxy_0.4-27 compiler_4.2.2 pillar_1.8.0 generics_0.1.3
[36] classInt_0.4-7 pkgconfig_2.0.3


And just for reference, here's the full error message I get when trying 2014:

Error in CPL_get_z_range(obj, 3) : z error - expecting three columns; Error: Your geometry data download failed. Please try again later or check the status of the Census Bureau website at https://www2.census.gov/geo/tiger/

Thanks so much for your help!

walkerke commented 1 year ago

@seandalby I think this might be a Mac issue with the sf package. Unlike other years, Census distributed the 2014 shapefiles as POLYGON Z, so I handle this internally with the tigris package to align with other years. However, it seems as though some Mac users are having trouble with sf and POLYGON Z geometries.

According to https://github.com/r-spatial/sf/issues/1592, upgrading to sf version 1.0.10 (the current dev version on GitHub) may solve it; remotes::install_github("r-spatial/sf"). Try that and let me know if it works!

If you are having trouble installing the dev version of sf, there is an open issue tracking that: https://github.com/r-spatial/sf/issues/2081

seandalby commented 1 year ago

@walkerke this is great, thanks so much for the info :) upgrading to the dev version of sf (1.0.10) worked - had to patch together some statements from these and other posts - specifically https://github.com/r-spatial/sf/issues/1894 - since the M1 mac's version of R 4.2.2 doesn't have sqlite or libproj available.

For anyone who is interested in this (relatively niche) solution, the following line of code worked for me:

install.packages("sf", repos = "https://r-spatial.r-universe.dev", type = "source", configure.args = c("--with-sqlite3-lib=/opt/homebrew/opt/sqlite/lib", "--with-proj-lib=/opt/homebrew/opt/proj/lib"))

seandalby commented 1 year ago

Also you may have to have homebrew installed and have already installed sqlite and proj:

brew install sqlite brew install proj

walkerke commented 1 year ago

@seandalby great news! Hopefully this will be helpful for other users.