[R-sig-hpc] foreach: using either %do% or %dopar% depending on condition
mat
matthieu.stigler at gmail.com
Mon May 3 12:45:02 CEST 2010
Hi
I wish to be able to substitute %do% or %dopar% depending on whether the
user wants or not to use the parallel feature. For this, I would do
something like:
if(hpc) foreach(icount(5), .combine = "rbind") %dopar%
else foreach(icount(5), .combine = "rbind") %do%
statement of function...
I did not succeed in doing it, I tried:
foreach(icount(5), .combine = "rbind") %do% else %dopar%
{
a<-runif(1)
b<-runif(1)
c(a,b)
}
Or tried to assign outside the operator:
"%my%" <-function(obj,ex) if(hpc=="none") "%dopar%" else "%dopar%"
foreach(icount(5), .combine = "rbind") %my% {
a<-runif(1)
b<-runif(1)
c(a,b)
}
But it fails... any idea?
Thanks a lot!!
Matthieu
More information about the R-sig-hpc
mailing list