[R-sig-hpc] nested foreach loops

Maas James Dr (MED) J.Maas at uea.ac.uk
Fri Aug 19 08:10:33 CEST 2011


I'm using the following nested foreach loop structure which seems to work quite well.

nsim = 1000 so the inner loop executes 1000 times.   I'd like to get the inner loop to randomly pick one result of the 1000 and graph it, but can't figure out how to create a function to do this.

the line

graphnum <- sample(1:nsim, 1)

would randomly generate a variable between 1 and 1000 that I can then use to test and do the graphing when true.  My question is where can I put this ?? I've tried putting it between the two foreach statments and that doesn't work.

Also, this structure is noted in the package definition for the foreach package ... but I can not find an example anywhere to show how to use them.  Would anyone have working examples?

when (cond)
e1 %:% e2

Thanks

Jim

======================

mpiresults <- foreach (j=1:nrow(inputpars), .combine=rbind) %:%
 foreach (i=1:nsim, .combine=rbind, .final=finalprocess) %dopar%

======================


===============================
Dr. Jim Maas
University of East Anglia



More information about the R-sig-hpc mailing list