Search code examples
rrasterr-mosaic

what does ""fun" is missing" error mean from mosaic() in [r] raster package?


I am trying to mosaic a (subset of a) list of rasters in [r] using mosaic() from the raster package.

I am basing my code on posts such as:

R: Raster mosaic from list of rasters?

I have tried both of these methods below,

allrasters_m$fun<-mean
allrasters_dnbr_mosaic<-do.call("mosaic",allrasters_m[grep("_dnbr",allrasters_m)])
allrasters_dnbr<-allrasters_m[grep("_dnbr",allrasters_m)]
allrasters_dnbr_mosaic<-do.call(mosaic,allrasters_dnbr)

and both give me this error message:

Error in .makeTextFun(fun) : argument "fun" is missing, with no default

any ideas? Thanks!

Here is some preceding code if that helps:

rastlist_m <- list.files(path=path, pattern='tif$', full.names=TRUE)

allrasters_m <- lapply(rastlist_m, raster)


Solution

  • I don't understand why, but 'merge' with the exact same syntax worked. allrasters_dnbr_mosaic<-do.call(merge,allrasters_m[grep("_dnbr",allrasters_m)]) so this is technically solved, but I don't understand why merge worked and mosaic didn't.