簡體   English   中英

如何加載.rds 文件?

[英]How to load .rds file?

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

對於上面的代碼,我得到以下錯誤:

警告消息:“文件 'gadm36_IND_2_sp.rds' 具有幻數 'X' 不推薦使用 2 之前的保存版本” 加載錯誤(“gadm36_IND_2_sp.rds”):錯誤的恢復文件幻數(文件可能已損壞)-沒有數據加載 Traceback:

  1. 負載(“gadm36_IND_2_sp.rds”)

在下面的代碼之后我正在運行:

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

您可以使用readRDS()而不是load() (與 .Rda 文件一起使用):

readRDS("gadm36_IND_2_sp.rds")

或使用readr package 和readr::read_rds() ,這基本上是相同的(它是上述的包裝器):

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM