Skip to content
Prev 15739 / 29559 Next

testing for a valid raster format before reading

On 27/07/12 11:35, Barry Rowlingson wrote:
Thanks Barry for your feedback.

Adding the 'silent' argument to 'try' produced the behaviour I wanted:

for(f in files){
   r = try(raster(f), silent=TRUE)
   if(inherits(r, "try-error")){
        warning("couldnt read ",f)
     }else{
        print(summary(r))
    }
   }
      Length       Class        Mode
       66548 RasterLayer          S4
Warning messages:
1: In eval(expr, envir, enclos) : couldnt read LHOAT-AGNPS2012.txt
2: In eval(expr, envir, enclos) : couldnt read SPSO.zip



All the best,

Mauricio