tidycensus error + SQL pseduocode

Hello!  First time poster, so please be gentle.  I'm relatively new to unaggregated Census data, although have a solid knowledge of R, statistics, and (if dated) survey methods.

I have spend a few hours over the long weekend trying to familiarize myself with tidycensus, PUMS data, and IPUMS/ipumsr.  tidycensus seems as if it should work, but I'm getting an error message: 

Error in curl::curl_fetch_memory(url, handle = handle) : Could not resolve host: api.census.gov

I don't know if it's related; I have tried to approaches to entering my key:


tidycensus::census_api_key(key =  "l0ts0fl3tt3r2andnumb3r2", install = TRUE)


temp <- get_pums(
variables = c("NRC", "FES", "WGTP"),
state = "AR",
survey = "acs1",
year = 2019,
rep_weights = "housing",
key = "l0ts0fl3tt3r2andnumb3r2",
show_call = TRUE

Ultimately, what I'm really trying to get is best represented by the following SQL pseudocod (although I could recode/rebucket the continuous NRC data):

SELECT NRC, FES, A_WGT_FACTOR -- number of children, adult gender/labor force, an appropriate weighting factor
FROM PUMS_DB -- the appropriate PUMS data source

Unless I misunderstand, I would have to download, unzip and then upload all the files to a database in order to execute the query above (?).

Any tips, tricks or hints would be most appreciated.  Thanks in advance and regards, T

  • Your tidycensus code looks good to me, but the error makes it seem like your machine is unable to connect to the API at all. Are you behind a firewall or proxy server that is preventing R from accessing web resources? Can you download any other file from the internet using R?

  • Thanks, Matt - thanks; great nudge: while I can access web resources incl. Census resources, apparently our firewall didn't like it whatever was happening in the background.  I copied my R Project to a different machine off-network it worked well.  Thanks again!  Best, Tarek

  • Glad you got it working! I've had to play around with my proxy settings at work to have R get around my firewall. Under the hood, tidycensus is using httr/curl to make the API request, so you might try looking at those settings -- here is some useful discussion of different options: stackoverflow.com/.../proxy-setting-for-r