我注意到,如果我使用 terra 包从存储在本地硬盘上的文件加载栅格,然后稍后加载工作区,则 SpatRaster 对象没有任何与其关联的数据。有没有办法在保存和加载工作空间时保留与 SpatRaster 对象关联的所有信息?
这是一个示例代码来说明这个问题:
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
#This produces the following output
r
#class : SpatRaster
#dimensions : 90, 95, 1 (nrow, ncol, nlyr)
#resolution : 0.008333333, 0.008333333 (x, y)
#extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax,
ymin, #ymax)
#coord. ref. : lon/lat WGS 84 (EPSG:4326)
#source : elev.tif
#name : elevation
#min value : 141
#max value : 547
sources(r)#this works
save.image("delete_if_found.RData")
rm(list = ls())
load("delete_if_found.RData")
r
#which returns the spatraster as
#class : SpatRaster
#Error in .External(list(name = "CppMethod__invoke_notvoid", address = \<pointer: (nil)\>, :
#NULL value passed as symbol address`
Run Code Online (Sandbox Code Playgroud)
I am currently importing all the relevant files again after loading the workspace, is there any other way to go about it?
Run Code Online (Sandbox Code Playgroud)
您可以使用writeRasterand then rast,也可以使用saveRDSand readRDS,但不能使用saveand load。
就我而言,这是一件好事,因为保存会话通常是一个坏主意(我希望 R 不会促使您这样做)。这很糟糕,因为您不应该用无缘无故的数据开始分析。相反,您可以将中间数据保存到文件中,并在下一步中再次读取它们。
| 归档时间: |
|
| 查看次数: |
769 次 |
| 最近记录: |