0

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))

```

Kurt
  • 3
  • 3
  • It would be much easier to help you if you provided some sort of minimal [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with specific functions that can be used for testing. – MrFlick Dec 14 '17 at 16:17
  • I'm not trying to solve a bug with `foreach` (there's likely no bug here), I just encountered an issue during deployment and trying to find a quick workaround. There's not much too reproduce here. I'll edit the question to give a more concrete idea. – Kurt Dec 14 '17 at 17:08
  • registerDoSeq() won't work? – F. Privé Dec 14 '17 at 18:41
  • In the particular example it might but `anotherPackage` does its own `registerDoParallel`, so probably no. – Kurt Dec 15 '17 at 08:46

0 Answers0