Skip to content

programmatically shift between %do% and %dopar% in foreach?

3 messages · Max Kuhn, Simon Urbanek, Brian G. Peterson

#
On Jan 8, 2013, at 11:40 AM, Max Kuhn wrote:

            
They are simply functions - you just forgot to quote it:
function (obj, ex)  

%...% are binary infix operators so if you use them as a symbol, you have to quote them.
It works, but if you want to keep the infix notation you have to use something like

`%op%` <- if (goParallel) `%dopar%` else `%do%`

otherwise for your suggestion you'd have to use the functional form:

operator(foreach(stuff), foo)

Cheers,
Simon
#
On 01/08/2013 10:40 AM, Max Kuhn wrote:
I always use %dopar%, and if necessary, e.g. in nested foreach loops, 
turn off parallelization on the nested workers after you're inside the 
worker loop, using a simple if construct as you describe.