I have just downloaded NDVI imagery from Google Earth Engine. The image was too big so it was divided into about 35 .tif files. Each tile has approximately 950 bands of NDVI values.

I am now trying to stitch the images back together in R. I have tried two different methods:

The first method which uses the raster package is really slow:


f <- list.files(path = "/scratch/MODIS_NDVI_TIFS", pattern = ".tif$", full.names = TRUE)

rl <- lapply(f, raster::brick)

m <- do.call(raster::mosaic, rl)


The second method I found discussed here which I modified for my use as such:


f <- list.files(path = "/scratch/MODIS_NDVI_TIFS", pattern = ".tif$", full.names = TRUE)

e <- extent(113.338953078, 153.569469029,-43.6345972634, -10.6681857235)

template <- raster(e)
proj4string(template) <- '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs '

writeRaster(template, file="Combine_NDVI.tif", format="GTiff",overwrite=TRUE)


However, I get an error in during the moasic_rasters call which states:

Error in strsplit(gsub(grep(cmd_output, pattern = "Size is ", value = TRUE),  : 
subscript out of bounds
Calls: mosaic_rasters -> gdalinfo
Execution halted

Any idea what is going on here? Are there better suggestions for combining these rasters together?

  • The appropriate raster method would be raster::merge(, overlap=FALSE). That should be faster than mosaic. Or try terra::merge Commented Nov 26, 2020 at 2:46

1 Answer 1


This Q & A should work, although you may run into memory issues depending on RAM etc

Error while combining multiple partially overlapping rasters into a single raster in R

  • What package does mosaicList come from?
    – Douglas
    Commented Nov 28, 2020 at 21:53
  • mosaicList is a custom function, detailed earlier in the thread- mainly built on raster Commented Dec 8, 2020 at 14:17

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.