I have a list of 420 rasterLayer .tif files that I need to create a rasterBrick from.
I first create a stack:
library(raster) rList <- list.files(pattern = ".tif") rasterStack <- stack(rList)
Which is quick, but when I try make a brick from the stack, it takes really long.
rasterBrick <- brick(rasterStack)
I'm currently working on a cluster. Is this a job for parallel computing? I tried the following:
library(parallel) numCores <- detectCores() rList <- list.files(pattern = ".tif") stacked <- stack(rList) rasterList <- mclapply(1:length(stacked), mc.cores = numCores, function(x) brick(stacked[[x]]))
But I get the following error:
Error in seq.default(i, length(X), by = cores) : 'by' argument is much too small Calls: mclapply -> lapply -> FUN -> seq -> seq.default Execution halted
I'm using all the cores available to me. Any suggestions please?