[R] parallel computing with foreach()

Kumar Mainali kpmainali at gmail.com
Thu Dec 7 07:03:46 CET 2017


I have used foreach() for parallel computing but in the current problem, it
is not working. Given the volume and type of the data involved in the
analysis, I will try to give below the complete code without reproducible
example.

In short, each R environment will draw a set of separate files, perform the
analysis and dump in separate folders.

splist <- c("juoc", "juos", "jusc", "pico", "pifl", "pipo", "pire", "psme")
covset <- c("PEN", "Thorn")

foreach(i = 1:length(splist)) %:%
foreach(j = 1:length(covset)) %dopar% {

spname <- splist[i]; spname
myTorP <- covset[j]; myTorP

DataSpecies = data.frame(prsabs = rep(1, 10), lon = rep(30, 10), lat =
rep(80, 10))
myResp = as.numeric(DataSpecies[,1])
myRespXY = DataSpecies[, c("lon", "lat")]
# directory of a bunch of raster files specific to each R environment
rastdir <- paste0(rootdir, "Current/", myTorP); rastdir
rasterc = list.files(rastdir, pattern="\\.tif$", full.names = T)
print(rasterc)
myExplc = stack(rasterc, RAT=FALSE)
}

I get the following error message that most likely generates while stacking
rasters because there are 25 rasters in the folder of each environment.
Also, in the normal for loop, this reads all fine.
Error in { :
  task 1 failed - "arguments imply differing number of rows: 25, 0"

Thank you.
ᐧ

	[[alternative HTML version deleted]]



More information about the R-help mailing list