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

get_decennial() returns error for 2020 data? #457

Closed westphl-pzrc closed 2 years ago

westphl-pzrc commented 2 years ago

Reposting from StackOverflow:

I've been working with census data from 2000, 2010, and 2020 for a local geography. My pulls for 2000 and 2010 work with no problem, but I get an error when I try to pull 2020 data.

`vars = c("P001001", #Total population "H013001", #Total households "P016002", #Total population under 18 "P020002" #Total!!Households with one or more people under 18 years )

import 2020 census data by block

phl_block_demos = get_decennial(geography = "block", year = 2020, variables = vars, geometry = T, #as an sf sumfile = "sf1", state = "PA", county = "Philadelphia", output = "wide") |> st_transform(crs = st_crs("EPSG:4326")) |> mutate(tract_num = substr(GEOID, 1, 11))`

R returns

Using the PL 94-171 Redistricting Data summary file Error in UseMethod("select") : no applicable method for 'select' applied to an object of class "character"

I get the same error message when I change the geography to "tract", when I set geometry = F, and when I run only the part of the code before the first pipe. The only thing that seems to work is picking a different census year, since 2000 and 2010 work fine.

Any ideas what the issue is? The data have been out since April, and I was hoping the issue would be fixed since my original post, but it still isn't working.

walkerke commented 2 years ago

Summary File 1 doesn't exist for 2020, and variables change from Census to Census. Right now, the only 2020 data we have is the PL 94-171 redistricting file. You should first do:

load_variables(2020, "pl")

to review variables from the 2020 PL file, then use those variable codes in your call to get_decennial().

I'd recommend reading my book for more information, in particular the following sections:

phcantis commented 2 years ago

Just curious - is there an anticipated time by which 2020 data will be available at the block level?

walkerke commented 2 years ago

@phcantis it's already available:

library(tidycensus)

get_decennial(
  geography = "block",
  variables = "P1_001N",
  state = "TX",
  county = "Jim Hogg",
  year = 2020
)
#> Getting data from the 2020 decennial Census
#> Using the PL 94-171 Redistricting Data summary file
#> Note: 2020 decennial Census data use differential privacy, a technique that
#> introduces errors into data to preserve respondent confidentiality.
#> ℹ Small counts should be interpreted with caution.
#> ℹ See https://www.census.gov/library/fact-sheets/2021/protecting-the-confidentiality-of-the-2020-census-redistricting-data.html for additional guidance.
#> This message is displayed once per session.
#> # A tibble: 769 × 4
#>    GEOID           NAME                                           variable value
#>    <chr>           <chr>                                          <chr>    <dbl>
#>  1 482479504001211 Block 1211, Block Group 1, Census Tract 9504,… P1_001N      0
#>  2 482479504001212 Block 1212, Block Group 1, Census Tract 9504,… P1_001N      0
#>  3 482479504001214 Block 1214, Block Group 1, Census Tract 9504,… P1_001N      0
#>  4 482479504001215 Block 1215, Block Group 1, Census Tract 9504,… P1_001N      0
#>  5 482479504001216 Block 1216, Block Group 1, Census Tract 9504,… P1_001N      0
#>  6 482479504001218 Block 1218, Block Group 1, Census Tract 9504,… P1_001N      0
#>  7 482479504001219 Block 1219, Block Group 1, Census Tract 9504,… P1_001N      0
#>  8 482479504001221 Block 1221, Block Group 1, Census Tract 9504,… P1_001N      0
#>  9 482479504001222 Block 1222, Block Group 1, Census Tract 9504,… P1_001N      0
#> 10 482479504001224 Block 1224, Block Group 1, Census Tract 9504,… P1_001N      0
#> # … with 759 more rows

Created on 2022-07-06 by the reprex package (v2.0.1)

phcantis commented 2 years ago

ah wow! thanks for the super quick response!