[R] merge large number of raster objects

Rolf Turner rolf.turner at xtra.co.nz
Fri Jun 10 10:13:51 CEST 2011


On 10/06/11 14:57, Ben Zaitchik wrote:
> Hello,
>
> I have a large number of raster objects in memory, with names RH100, 
> RH101, RH102, etc. (myobjects <- ls(pattern='^RH')).
> These rasters are sections of a continuous map, and I would like to 
> combine them using the RasterObject merge tool in package 'raster.'
>
> Merge expects an input list of raster objects (outmap<-merge(x, y, 
> ...), where x, y, and ... are raster objects).  I can run the command 
> successfully if I type in every raster object that I want to merge, 
> but this is impractical for the large number of objects I'm combining.
>
> I would like to apply merge to a list of object names defined using 
> some kind of wildcard-based list command, but I'm struggling to find 
> the right data types in R.
>
> Is there some way to convert a vector of strings (e.g., 
> as.vector(ls(pattern='^RH'))) to a vector of object names (as.names??) 
> that could be specified as the input to the merge function?  What I'd 
> really like to do is something like outmap<-merge(myobjects[1:40]), in 
> order to merge the 40 raster objects, but I recognize that it might 
> not be so simple.
>
> Advance apologies if this is already dealt with on the help list . . . 
> I've gone in circles on wildcard, lapply, and names threads and 
> haven't managed to get anything to work.

I think that

     outmap <- do.call(merge,myobjects)

should work for you.

     cheers,

         Rolf Turner



More information about the R-help mailing list