From: David M Smith <david_at_revolution-computing.com>

Date: Thu, 29 Apr 2010 15:44:34 -0700

Date: Thu, 29 Apr 2010 15:44:34 -0700

[This relates to the foreach function in library(foreach)]

So what you probably really want is code like this:

test <- foreach(i = c(1.25, 1.50)) %dopar% some_timeconsuming_operation(i)

and then (if you really need the variables named as specified)

v <- c(1,25,1.50)

for (i in seq(along=v)) assign(paste("test_",v[i],sep=""),test[[i]])

some_timeconsuming_function <- function(i) i

but that's not timeconsuming, and so you're not going to get any benefit from parallelization.

On Thu, Apr 29, 2010 at 2:07 PM, Vivek Ayer <vivek.ayer_at_gmail.com> wrote:

> Hi guys,

*>
**> I was wondering why this piece of code doesn't work:
**>
**> foreach (i = c(1.25,1.50)) %dopar% {
**> assign(paste("test_",i,sep=""),i)
**> }
**>
**> but, this does:
**>
**> foreach (i = c(1.25,1.50)) %do% {
**> assign(paste("test_",i,sep=""),i)
**> }
**>
**> Obviously, the difference is %dopar% vs. %do%. If I use %do%, I get
**> objects test_1.25 and test_1.50, but I don't get these objects if I
**> use %dopar% even though it seemed to run through the loop in parallel.
**>
**> Thanks in advance,
**> Vivek
**>
**> ______________________________________________
**> R-help_at_r-project.org mailing list
**> https://stat.ethz.ch/mailman/listinfo/r-help
**> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
**> and provide commented, minimal, self-contained, reproducible code.
**>
*

-- David M Smith <david_at_revolution-computing.com> VP of Marketing, REvolution Computing http://blog.revolution-computing.com Tel: +1 (650) 330-0553 x205 (Palo Alto, CA, USA) Download REvolution R free: www.revolution-computing.com/downloads/revolution-r.php ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.Received on Thu 29 Apr 2010 - 22:47:02 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Fri 30 Apr 2010 - 01:00:16 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*