-3

Attempting to use tidycensus package to download data.

As I read it, tidycensus supports blocks for 2000. Tract works, block group works, blocks fail

library(tidycensus)
library(tidyverse)
library(viridis)
library(ggplot2)
library(dplyr)

#------Get Decennial Census Data
ut2000tract <- get_decennial(geography = "tract", variables = "P001001", 
year = 2000, sumfile = "sf1", key = mykey, state = "49", county = "035", 
geometry = FALSE)
ut2000BG <- get_decennial(geography = "block group", variables = 
"P001001", year = 2000, sumfile = "sf1",
key = mykey, state = "49", county = "035", geometry = FALSE)
ut2000block <- get_decennial(geography = "block", variables = "P001001", 
year = 2000, sumfile = "sf1", key = mykey, state = "49", county = "035", 
geometry = FALSE)

Generating the following error:

1 "Checking SF3 API for data..." 1 "Client error Bad Request Client error: (400) Bad Request" Error in stri_replace_first_regex(string, pattern, fix_replacement(replacement), : argument str should be a character vector (or an object coercible to) Error in gather.default(., key = variable, value = value, -GEOID, -NAME) :
object 'NAME' not found

I know block should be a valid geometry; I just want a count of population/block, which is in the Census 2000 SF1 file. Not sure why tidycensus is not working. Pulling data for 2010 seems to work. But not 2000.

totalcensus doesn't cover Census 2000

Mox
  • 511
  • 5
  • 15
  • 1
    https://stackoverflow.com/questions/45109241/r-tidycensus-download-all-block-groups – Mox Dec 20 '17 at 03:45
  • 4
    Possible duplicate of [r tidycensus download all block groups](https://stackoverflow.com/questions/45109241/r-tidycensus-download-all-block-groups) – jesstme Dec 20 '17 at 03:59
  • I wish. It may just be making a very basic error. But I can't figure out what. – Mox Dec 20 '17 at 04:05
  • Can you share more/all/a short version of your code so that we can try it out ourselves? – jesstme Dec 20 '17 at 04:12
  • Apart from some library loads, the above is all of it. Tract works, block group works, block fails. – Mox Dec 20 '17 at 04:14
  • If the packages are necessary for the code to work, please do share which library loads. Also what is the "..." at the end of the first chunk of code? – jesstme Dec 20 '17 at 04:16
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161568/discussion-between-jesstme-and-mox). – jesstme Dec 20 '17 at 04:19
  • https://github.com/walkerke/tidycensus/issues/13 – Mox Dec 20 '17 at 04:32
  • Remember that not all data is available at the block level. – Elin Dec 20 '17 at 05:02
  • Checked; the variable I'm using is a simple count of population, available for all levels of geography. – Mox Dec 20 '17 at 05:19

1 Answers1

1

I'm the author of tidycensus; I answered this on the GitHub issues page (https://github.com/walkerke/tidycensus/issues/51) but I'll cross-post here.

This is due to a limitation of the Census API; block data for 2000 are only available by Census tract within counties in the API, and I don't have functionality in the package to handle this at the moment. I've added a new error message in the package to explain this. My recommended alternatives:

  • Use NHGIS (http://www.nhgis.org) to download the data and the ipumsr package (https://github.com/mnpopcenter/ipumsr) which provides an excellent new interface to use it in R.
  • Use the censusapi package (https://github.com/hrecht/censusapi) which lets you construct any Census API query you want. If you were to generate a vector of tract IDs for your desired county, you could likely use purrr's map_df() to iterate through these IDs and get the output you need.
kwalkertcu
  • 1,011
  • 6
  • 8
  • https://stackoverflow.com/questions/45109241/r-tidycensus-download-all-block-groups/47683019?noredirect=1#comment85087712_47683019 – Mox Mar 07 '18 at 23:43