I appear to be having a Windows-only issue reading rasters using Rscript and a direct call to the raster package. I have the latest version of the raster package (2.5-2). Running R 3.2.1 in Windows 2008 R2.
Given the following:
library(raster)
j <- raster(matrix(rnorm(100), ncol=10, nrow=10))
writeRaster(j, 'j.tif')
If I start a new R session (or not), this works in R:
library(raster)
j <- raster('j.tif')
So does this (again, in a new session):
j <- raster::raster('j.tif')
If I try it from the command line and using Rscript, this works:
C:\> Rscript -e "library(raster); raster('j.tif')
But this does NOT work:
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
Rscriptcalls work fine for me (R 3.2.3, 64-bit; Windows 8.1; raster 2.5-2)Rscriptdoesn't load the methods package andraster:::.rasterFromGDAL(which is called byraster::rasterin this case) needsmethods::checkAtAssignment. BUT, not sure why it works elsewhere. Not in a position to immediately upgrade to 3.2.3 so I'm going to keep looking closer.