I encountered a problem in my workflow with R that prevents me from using certain kinds of parallelization.
In this particular case, myCustomPackage imports and uses problematic_function which is exported from anotherPackage. problematic_function uses %dopar% operator from foreach for certain calculations and hence imports it from foreach. Due to certain reasons usage of %dopar% results in errors and I would like to find a workaround that I could apply on the fly.
Since parallelization is not really essential in this case, as a short-term solution I would like to fully override %dopar% by replacing it with %do% everywhere, which actually works fine in my case.
I tried several variations of assignInNamespace('%dopar%', '%do%', 'foreach') but with little success.
Maybe someone has a better idea on this? I'd really like to avoid messing with the source code of anotherPackage for the time being.
EDIT. To illustrate with a more concrete example, here's an equivalent issue. How to make this code run with %do% despite allowParallel = TRUE.
library(caret)
library(party)
library(foreach)
library(doParallel)
library(parallel)
data(BloodBrain)
cl <- makeCluster(1)
registerDoParallel(cl)
treebag <- bag(bbbDescr, logBBB, B = 10,
bagControl = bagControl(fit = ctreeBag$fit,
predict = ctreeBag$pred,
aggregate = ctreeBag$aggregate,
allowParallel = TRUE))
```