1

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)

ali
  • 29
  • 1
  • 7
  • 1
    You need to specify the function to use in overlapping areas, for example, mean, min or max. Something like: `mosaic(...., fun = mean)` – Jonathan V. Solórzano Jan 28 '20 at 21:23
  • Sorry, I forgot to add the `allrasters_m$fun<-mean` statement I had run prior to the first line of code in this post. I have also tried two other ways 1) `allrasters_dnbr_mosaic<-do.call(mosaic,allrasters_m[grep("_dnbr",allrasters_m)], fun=mean)` and 2) `allrasters_dnbr_mosaic<-do.call(mosaic,allrasters_dnbr, fun=mean)` and both give me the error message "Error in do.call(mosaic, allrasters_m[grep("_dnbr", allrasters_m)], : unused argument (fun = mean)" – ali Jan 29 '20 at 13:49
  • Note - I have intentionally masked these rasters so that there is no overlap, i.e. they look like spots on a giraffe. – ali Jan 29 '20 at 13:51
  • I wonder if mosaic(), even with fun=mean never worked because there is no overlapping area in the rasters I am mosaicking, that would explain the error message 'unused argument(fun=mean)'. Merge() was able to handle combining multiple rasters that have no overlap. – ali Jan 31 '20 at 14:42

1 Answers1

0

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.

ali
  • 29
  • 1
  • 7