R.R.P
R.R.P

Reputation: 21

How to load .rds file?

library(ggmap) # -- for geocoding, obtaining city locations
load("gadm36_IND_2_sp.rds")
ind2 = gadm

For the above code i am gettig the below error:

Warning message: “file ‘gadm36_IND_2_sp.rds’ has magic number 'X' Use of save versions prior to 2 is deprecated” Error in load("gadm36_IND_2_sp.rds"): bad restore file magic number (file may be corrupted) -- no data loaded Traceback:

  1. load("gadm36_IND_2_sp.rds")

After that below code i am running:

# plotting districts of a State, in this case West Bengal
wb2 = (ind2[ind2$NAME_1=="West Bengal",])

nam = c("Purulia","Bankura","Midnapur")
pos = geocode(nam)
tlat = pos$lat+0.05    # -- the city name will be above the marker
cities = data.frame(nam, pos$lon,pos$lat,tlat)
names(cities)[2] = "lon"
names(cities)[3] = "lat"


text1 = list("panel.text", cities$lon, cities$tlat, cities$nam,col="red", cex = 0.75)
mark1 = list("panel.points", cities$lon, cities$lat, col="blue")
text2 = list("panel.text",87.0,26.0,"GADM map", col = "dark green", cex = 1.2)
spplot(wb2, "NAME_1",
sp.layout=list(text1,mark1, text2),
main="West Bengal Districts",
colorkey=FALSE, scales=list(draw=TRUE))

Upvotes: 0

Views: 7264

Answers (1)

user13653858
user13653858

Reputation:

You can use readRDS() instead of load() (which is used with .Rda files):

readRDS("gadm36_IND_2_sp.rds")

or use readr package with readr::read_rds(), which is basically the same (it's a wrapper for the above):

library(readr)
read_rds("gadm36_IND_2_sp.rds")

Upvotes: 3

Related Questions