[R] I might be dumb : a simple question about "foreach"

Olivier ETERRADOSSI olivier.eterradossi at ema.fr
Mon Jul 20 15:14:50 CEST 2009


Thanks Michael
I already tried the curly brackets before my first post... no hope, it
didn't change anything.
Turning %do% into %dopar% didn't work as well...
Do you suggest some Windows related behaviour ?
regards, Olivier


Michael Knudsen-2 wrote:
> 
> On Mon, Jul 20, 2009 at 2:48 PM, Olivier
> ETERRADOSSI<Olivier.Eterradossi at ema.fr> wrote:
> 
>>>  x <- foreach(i = 1:3) %do% sqrt(i)
>>
>> and get :
>>>
>>> Erreur dans sqrt(i) : indice hors limites ( i.e. "error in sqrt(i) :
>>> index
>>> out of bounds")
> 
> I once got similar errors because I didn't encapsulate the part af
> %do% or %dopar% in curly brackets. Try
> 
> x <- foreach(i = 1:3) %do% { sqrt(i) }
> 
> I should say, however, that in this particular case, your original
> code evaluates without errors on my computer (Mac OSX 10.5.7 with R
> 2.9.1).
> 
> By the way, remember to use %dopar% instead of %do%, if you want to
> take advantage of multiple cores. While being totally ecstatic after
> discovering foreach, I wrote the following (very simple) guide:
> 
> http://lifeofknudsen.blogspot.com/2009/07/most-of-work-i-do-in-r-has-to-do-with.html
> 
> Maybe you'll find it useful, maybe not.
> 
> -- 
> Michael Knudsen
> micknudsen at gmail.com
> http://lifeofknudsen.blogspot.com/
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/I-might-be-dumb-%3A-a-simple-question-about-%22foreach%22-tp24569290p24569609.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list