我似乎在使用Rscript读取栅格和直接调用raster包时遇到了Windows特有的问题。我有最新版本的raster包(2.5-2)。在Windows2008 R2中运行R 3.2.1。
假设有以下情况:
library(raster)
j <- raster(matrix(rnorm(100), ncol=10, nrow=10))
writeRaster(j, 'j.tif')如果我启动一个新的R会话(或不启动),这在R中工作:
library(raster)
j <- raster('j.tif')这样做(同样,在新的会话中):
j <- raster::raster('j.tif')如果我从命令行使用Rscript进行尝试,这是可行的:
C:\> Rscript -e "library(raster); raster('j.tif')但这是行不通的:
C:\> Rscript -e "raster::raster('j.tif')"
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file.
Calls: <Anonymous> -> <Anonymous> -> .local -> .rasterObjectFromFile
Execution halted发布于 2016-02-21 14:08:45
c:/中是否存在该文件?你能做到:
Rscript -e "file.exists('j.tif')"我认为你关于Rscript没有加载方法包的说法是对的。但是raster依赖于它并加载它:
Rscript -e "library(raster); sessionInfo()"
#Loading required package: methods
#Loading required package: sp
#R Under development (unstable) (2016-01-09 r69890)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 7 x64 (build 7601) Service Pack 1
#attached base packages:
#[1] methods stats graphics grDevices utils datasets basehttps://stackoverflow.com/questions/35515422
复制相似问题