Calflamesfann
Calflamesfann

Reputation: 143

Error in readOGR(dsn, layer) : could not find function "readOGR"

I am very new to R and so what does this mean? Does this tell me that I need to install some package named "ReadOGR"

I am following along using code written by someone else in an effort to generate a heat map. here is the current section to give some context.

   setwd("C:/Users/Someone/Documents/R")
   dsn <- "cb_2017_us_state_20m.shp"
   layer <- "cb_2017_us_state_20m"
   cb5 = readOGR(dsn, layer)

Installed rgdal to no success. Tried library(rgdal)

  library(rgdal) 
  Loading required package: sp
  rgdal: version: 1.3-9, (SVN revision 794)
   Geospatial Data Abstraction Library extensions to R successfully loaded
  Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
  Path to GDAL shared files: C:/Users/trwilcox/Documents/R/win- 
  library/3.5/rgdal/gdal
  GDAL binary built with GEOS: TRUE 
  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
  Path to PROJ.4 shared files: C:/Users/someone/Documents/R/win- 
  library/3.5/rgdal/proj
  Linking to sp version: 1.3-1 
 Warning messages:
  1: package ‘rgdal’ was built under R version 3.5.2 
  2: package ‘sp’ was built under R version 3.5.2 
 > cb5 = readOGR(dsn, layer)
 Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = 
  use_iconv,  : 
   Cannot open data source

Upvotes: 0

Views: 10193

Answers (1)

LocoGris
LocoGris

Reputation: 4480

Try:

setwd("C:/Users/Someone/Documents/R")
dsn <- "cb_2017_us_state_20m.shp"
cb5 = readOGR(dsn)

Also, you can find the original files here: https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html. Maybe there are some extra info there you want to use. You have to use the one with .shp not the shp.xlm If you do not have it, download from the link above!!! It should work now, if not, happy to help you!

Upvotes: 1

Related Questions