0

I have a problem with reading a shapefile. The code below returned the error of "could not find function "read_shape"." This used to work properly before upgrading my R/Rstudio to a newer version. Currently, I am using Version 1.1.463 of Rstudio, and R version 4.0.3.

Here is my code:

    usshapefile <- "cb_2017_us_county_500k.shp"
usgeo <- read_shape(file=usshapefile, as.sf = TRUE)
Nader Mehri
  • 514
  • 1
  • 5
  • 21
  • 2
    Did you load the library? `library(tmap)` ? Or try `usgeo <- tmap::read_shape(file=usshapefile, as.sf = TRUE)` – Ronak Shah Nov 16 '20 at 03:07
  • 1
    I think `read_shape` was moved to package `tmaptools`, and then [removed from tmaptools](https://www.rdocumentation.org/packages/tmaptools/versions/3.1/topics/deprecated_functions) and put in `oldtmaptools`. So the function doesn't exist in the latest version of `tmap`. It was a wrapper around `rgdal::readOGR` so perhaps use that instead. – neilfws Nov 16 '20 at 03:15
  • Thanks for your comments. Yes, I loaded the tmap and tmaptools libraries. I tried to install the oldtmaptools but it appears that there is not such a library. Could you please clarify on "It was a wrapper around rgdal::readOGR so perhaps use that instead". – Nader Mehri Nov 16 '20 at 03:34
  • 1
    `oldtmaptools` is not in CRAN, it's hosted at Github, so you'd need to install `devtools` and then install using `install_github("mtennekes/oldtmaptools")`. "Wrapper" means that `readOGR` from `rgdal` should do the same job, but the syntax and options might be different. – neilfws Nov 16 '20 at 21:06
  • Thanks. I installed devtools and then used install_github("mtennekes/oldtmaptools") to install oldmaptools. but got this: Error in install_github("mtennekes/oldtmaptools") : could not find function "install_github" – Nader Mehri Nov 16 '20 at 21:30

0 Answers0