2

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
2
  • 2
    I can't reproduce this on my system - both Rscript calls work fine for me (R 3.2.3, 64-bit; Windows 8.1; raster 2.5-2) Commented Feb 19, 2016 at 23:51
  • 1
    I've gotten as far as figuring out that it's because Rscript doesn't load the methods package and raster:::.rasterFromGDAL (which is called by raster::raster in this case) needs methods::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. Commented Feb 21, 2016 at 0:21

1 Answer 1

1

Does the file exist in c:/ ? Can you do:

Rscript -e "file.exists('j.tif')"

I think you are right about Rscript not loading the methods package. But raster depends on it and loads it:

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  base
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.