Olivier ETERRADOSSI
2009-Jul-20 12:48 UTC
[R] I might be dumb : a simple question about "foreach"
Hi list, My attention was drawn to the foreach package by recent posts...I decided to have a look... I'm using R.2.9.1 on Windows, I have downloaded the foreach package today (v 1.2.1), together with iterators (v. 1.0.1) and codetools (v.0.2-2). Full of hope I try the most simple thing of all out of the package vignette :> 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")but when trying :> x<-foreach(i = 1:3) %do% print(sqrt(i))I get :> [1] 1 > [1] 1.414214 > [1] 1.732051 > Erreur dans print(sqrt(i)) : indice hors limitesProbably I didn't drink enough coffee this morning and I'm still asleep : it is obvious that I miss a point... but I am unable to see which one. Any help appreciated ! Many thanks, and very best regards Olivier -- Olivier ETERRADOSSI Ma?tre-Assistant CMGD / Equipe "Propri?t?s Psycho-Sensorielles des Mat?riaux" Ecole des Mines d'Al?s H?lioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 tel std: +33 (0)5.59.30.54.25 tel direct: +33 (0)5.59.30.90.35 fax: +33 (0)5.59.30.63.68 http://www.ema.fr
Michael Knudsen
2009-Jul-20 13:05 UTC
[R] I might be dumb : a simple question about "foreach"
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/
David M Smith
2009-Jul-20 18:28 UTC
[R] I might be dumb : a simple question about "foreach"
A user in Japan reported a similar problem on the Revolutions blog ( http://bit.ly/FKP2I ), and my best guess is that it's an (unintended!) effect of using locales. The developers in New Haven are looking at it, and I expect they'll be able to post an update to CRAN soon. # David Smith On Mon, Jul 20, 2009 at 5:48 AM, Olivier ETERRADOSSI < Olivier.Eterradossi@ema.fr> wrote:> Hi list, > My attention was drawn to the foreach package by recent posts...I decided > to have a look... > I'm using R.2.9.1 on Windows, I have downloaded the foreach package today > (v 1.2.1), together with iterators (v. 1.0.1) and codetools (v.0.2-2). > Full of hope I try the most simple thing of all out of the package vignette > : > >> 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") >> > but when trying : > > x<-foreach(i = 1:3) %do% print(sqrt(i)) >> > I get : > > [1] 1 >> [1] 1.414214 >> [1] 1.732051 >> Erreur dans print(sqrt(i)) : indice hors limites >> > Probably I didn't drink enough coffee this morning and I'm still asleep : > it is obvious that I miss a point... but I am unable to see which one. > Any help appreciated ! Many thanks, and very best regards Olivier > > -- > Olivier ETERRADOSSI > Maître-Assistant > CMGD / Equipe "Propriétés Psycho-Sensorielles des Matériaux" > Ecole des Mines d'Alès > Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 > tel std: +33 (0)5.59.30.54.25 > tel direct: +33 (0)5.59.30.90.35 fax: +33 (0)5.59.30.63.68 > http://www.ema.fr > > ______________________________________________ > R-help@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@revolution-computing.com> Director of Community, REvolution Computing www.revolution-computing.com Tel: +1 (206) 577-4778 x3203 (San Francisco, USA) Check out our upcoming events schedule at www.revolution-computing.com/events [[alternative HTML version deleted]]