I am trying to implement an R parallel loop iteration, but not sure how to condition it so that it will only need to return (row-bind append) result to the main result dataset if certain condition is met. Meaning, in some situation I do not want the particular iteration step to return anything. Pseudo-example below:
library(foreach)
library(doParallel)
registerDoParallel(makeCluster(detectCores() - 1))
final.result <- foreach(i = 1:100, .combine=cbind) %dopar% {
getResultDS = functionXYZ()
...
...
...
# append function result to final.result only if getResultDS[1] > 0
if (getResultDS[1,] == 0) {
getResultDS
}
}
...
...
...
Appreciate anyone's input here, thanks!