Getting Census boundary files with tigris, sp packages

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")

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!


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.


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



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


1 Like

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