maycca
maycca

Reputation: 4090

Error raster file seems to not exist in R

I have reinstalled R because of disfunction of pgirmess package. I have re-downloaded all necessary packages. I have used the same script that works fine before re-installation. However I cant read raster objects and I obtain a message:

Error: file.exists(filename) is not TRUE

but I know that these files exist!

If I am running {raster} exemple

f <- system.file("external/test.grd", package="raster")
f
r <- raster(f)

{raster} and R works fine. Any help? I cant really imagine where the problem could be! (I have verified a working directory, check file existence in different program, restarted R and computer, tried to read different rasters from different directories...). When I try to read tables, it works fine. Only raster files are problematic. Thank you really much

How it looks in R:

> getwd()                                               # where am I working?
[1] "D:/UEL/Data/2014_05_21 classify final/indexy"
> file.exists("n_msi2011.img")                          # does file exist?
[1] TRUE
> a<-raster("D:/UEL/Data/2014_05_21 classify final/indexy/n_msi2011.img") # read    
                                                                          # existing  
                                                                          # file
Error: file.exists(filename) is not TRUE                # why???

Upvotes: 2

Views: 6679

Answers (2)

user49017
user49017

Reputation: 137

I had the same problem. It went away after I installed and loaded the package rgdal

See code below:

library(raster)
library(rgdal)
object <- raster("object.img")

Upvotes: 5

maycca
maycca

Reputation: 4090

the problem was in not well updated {sp} package. After its reinstallation and then updating {raster} pkg the problem was fixed.

Recommendation for the futur reinstalation of R (Win7):

  1. uninstall R (Start->Control Panel-> Uninstall a Program)
  2. install new R version
  3. from directory of your previous R version (C:/Program Files/.../R/R-3.0.2) copy all
    packages in /R/R-3.0.2/Library (R keep all your previous installations)
  4. paste copied packages into new created R version R/R-3.1.1/Library
  5. run new R
  6. insert in R console:update.packages(checkBuilt=TRUE, ask=FALSE)

and it has to work!

Upvotes: -1

Related Questions