Getting Census boundary files with tigris, sp packages

Hello!
I have successfully installed and loaded the tigris package. Using the counties() function in tigris, I was able to pull up the shapefile with no problem.

However, when I use the tracts() function, I get the following error message:

Get a Census tracts dataset for Denver County, Colorado and plot it

denver_tracts <- tracts(state = "CO", county = "Denver")
plot(denver_tracts)

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer

I am using RStudioCloud on a Windows 10 build. I have also ensured that tigris and sp were updated. Thanks!

Greg

Hmm. I'm not able to replicate that error in my RStudio Cloud account. You could try to request an sf object (instead of sp) from tigris and see if you have any better luck:

denver_tracts <- tracts(state = "CO", county = "Denver", class = "sf")
1 Like

I see @mfherman has beaten me, yet again :slight_smile:

But since I have the code & example already prepared you will have to excuse me for sharing...
{sf} version seems to work OK.

library(sf)

denver_tracts <- tigris::tracts(state = "CO", county = "Denver", class = "sf")

plot(st_geometry(denver_tracts))

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Hey, thank you for your assistance. That seemed to do the trick.

Greg

1 Like