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

Errors with 2000 decennial census #96

Closed sbatia closed 6 years ago

sbatia commented 6 years ago

I’m having issues with 2000 decennial census data for some variables. This was working a few weeks ago and has not been changed since then. I am working with data from Mecklenburg County, NC. *The 2010 and 2016 ACS data still works fine. Here is a small subset of the code and the error it is now throwing:

code

reading needed packages

library(tidycensus) ##functions: get_acs, get_decennial library(tidyverse) ##functions: mutate, library(tidyr) ##functions: spread library(dplyr) ##functions: rowwise, select, %>% options(tigris_use_cache = TRUE)

intro

census API only needs to be done once

census_api_key("e5679009ded6f1bbc11f86d365528a13dfff2779", install=TRUE)

load summary files list of variables

var1990_sf1 <- load_variables(1990, "sf1", cache=TRUE) var2000_sf1 <- load_variables(2000, "sf1", cache=TRUE) var2000_sf3 <- load_variables(2000, "sf3", cache=TRUE)

var2010_sf1 <- load_variables(2010, "sf1", cache=TRUE)

var2010_sf2 <- load_variables(2010, "sf2", cache=TRUE)

var2010 <- load_variables(2010, "acs5", cache=TRUE) var2016 <- load_variables(2016, "acs5", cache=TRUE)

View(var2000_sf1)

means of transport

2000: SF3: P30

transp2000 <- get_decennial(geography = "block group", variables = c(Total = "P030001", Alone = "P030003", CarPL = "P030004", bus = "P030006", streetcar = "P030007", subway = "P030008", railroad = "P030009", ferry = "P030010", Taxi = "P030011", Moto = "P030012", Bike = "P030013", Walk = "P030014", Other = "P030015", Home = "P030016"), year = 2000, sumfile = sf3, state = 37, county = 119) %>% select(1,3,4) %>% spread(variable, value) %>% mutate(Public = bus+streetcar+subway+railroad+ferry) %>% select(1:3,5,7:9,13:16)

And here is the error being thrown: Error in stri_replace_first_regex(string, pattern, fixreplacement(replacement), : argument 'str' should be a character vector (or an object coercible to) Error in gather(data, key_col = compat_as_lazy(enquo(key)), value_col = compat_as_lazy(enquo(value)), : unused argument (-NAME)

walkerke commented 6 years ago

Yes - I'm guessing this has something to do with https://github.com/walkerke/tidycensus/issues/91. The Census Bureau changed a bunch of variable IDs and won't be providing a complete variable mapping. The documentation on the Census Bureau website (which tidycensus pulls in load_variables()) also hasn't been updated so some variable IDs returned by that function will be incorrect.

Until the Census Bureau updates their variable documentation I'm not sure there's much I can do. Often this can be fixed by removing a 0; however I'd have to check your example when I get a minute.

walkerke commented 6 years ago

I just checked your example and it runs fine for me. Perhaps there was an issue with the Census API at that particular moment? Please try again and re-open if you are experiencing the same issue.