0

I am trying to pull geometries from tidycensus but keep running into errors.

I enter the following code:

### Load packages

library(tidycensus)
library(dplyr)
library(tidyverse)

### Install api key

census_api_key("<mykey>")

### Pull data

cook<-get_acs(geography = "tract",variables = c(medincome = "B06011_001"),year=2018,survey = "acs5",state = "IL",
              county = "Cook",geometry = T)

But I receive the following output and error:

Getting data from the 2014-2018 5-year ACS
Using FIPS code '17' for state 'IL'
Using FIPS code '031' for 'Cook County'
Error: All columns in a tibble must be vectors.
x Column `geometry` is a `sfc_MULTIPOLYGON/sfc` object.
Run `rlang::last_error()` to see where the error occurred.

I follow the prompt and run rlang::last_error() and get:

<error/tibble_error_column_scalar_type>
All columns in a tibble must be vectors.
x Column `geometry` is a `sfc_MULTIPOLYGON/sfc` object.
Backtrace:
  1. tidycensus::get_acs(...)
  9. dplyr:::right_join.data.frame(geom, dat2, by = "GEOID")
 12. dplyr::tbl_df(x)
 14. tibble:::as_tibble.data.frame(data, .name_repair = "check_unique")
 15. tibble:::lst_to_tibble(unclass(x), .rows, .name_repair)
 16. tibble:::check_valid_cols(x)
Run `rlang::last_trace()` to see the full context.

I follow the prompt and run rlang::last_trace() and get:

<error/tibble_error_column_scalar_type>
All columns in a tibble must be vectors.
x Column `geometry` is a `sfc_MULTIPOLYGON/sfc` object.
Backtrace:
     x
  1. \-tidycensus::get_acs(...)
  2.   +-right_join(geom, dat2, by = "GEOID") %>% st_as_sf()
  3.   | \-base::eval(lhs, parent, parent)
  4.   |   \-base::eval(lhs, parent, parent)
  5.   +-dplyr::right_join(geom, dat2, by = "GEOID")
  6.   +-sf:::right_join.sf(geom, dat2, by = "GEOID")
  7.   | \-sf:::sf_join(NextMethod(), attr(x, "sf_column"))
  8.   +-base::NextMethod()
  9.   \-dplyr:::right_join.data.frame(geom, dat2, by = "GEOID")
 10.     +-base::as.data.frame(...)
 11.     +-dplyr::right_join(tbl_df(x), y, by = by, copy = copy, ...)
 12.     \-dplyr::tbl_df(x)
 13.       +-tibble::as_tibble(data, .name_repair = "check_unique")
 14.       \-tibble:::as_tibble.data.frame(data, .name_repair = "check_unique")
 15.         \-tibble:::lst_to_tibble(unclass(x), .rows, .name_repair)
 16.           \-tibble:::check_valid_cols(x)

The function get_acs() works fine when geometry=F. I'm not sure where to go from here. Any ideas?

dkro
  • 193
  • 1
  • 8

0 Answers0