Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-30 Thread Patrick Burns
can Murdoch [mailto:murd...@stats.uwo.ca] Sent: Thursday, January 29, 2009 9:54 AM To: David Reiner Cc: Henrik Bengtsson; r-help@r-project.org; SnowManPaddington Subject: [SPAM] - Re: [R] scoping rules for 'for' [was - Re: for/if loop ] - Found word(s) list error in the Text body Fe

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread Gabor Grothendieck
On Thu, Jan 29, 2009 at 12:05 PM, Henrik Bengtsson wrote: > PS. About the double-letter index (e.g. ii vs. i); A few years ago > someone suggested me to use this, because it is much easier to search > for 'ii' in an editor compared with a single-letter 'i'. So true. I > made the move immediatel

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread SnowManPaddington
gt; Thanks to all for the clarifications. > -- David > > > -Original Message- > From: Duncan Murdoch [mailto:murd...@stats.uwo.ca] > Sent: Thursday, January 29, 2009 9:54 AM > To: David Reiner > Cc: Henrik Bengtsson; r-help@r-project.org; SnowManPaddington > Su

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread davidr
, January 29, 2009 9:54 AM To: David Reiner Cc: Henrik Bengtsson; r-help@r-project.org; SnowManPaddington Subject: [SPAM] - Re: [R] scoping rules for 'for' [was - Re: for/if loop ] - Found word(s) list error in the Text body Feel free to do what you like to the variable within the lo

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: > On 1/29/2009 10:39 AM, dav...@rhotrading.com wrote: > >> And if the loop variable does not exist before the 'for', why is it >> created in the parent(?) environment at all? > > It's created in the current evaluation frame, because that's where > everything gets created un

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread Henrik Bengtsson
Thanks for straighten this out. Sorry for my misleading suggestion that "special" scoping rules comes into play; it is just about reassignments at the beginning of each loop. Here is a slightly better illustration: ii <- "start"; cat("ii:",ii,"\n"); for (ii in 1:2) { cat("Outer ii:",ii,"\n");

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread Duncan Murdoch
On 1/29/2009 11:06 AM, Patrick Burns wrote: Certainly not a complete description, but 'The R Inferno' talks about this on page 62. Hmmm, I don't think I agree with that description. There's only one object named i in that example (which was for (i in 1:6) { cat('\n i is', i, '\n\n') for

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread Patrick Burns
Certainly not a complete description, but 'The R Inferno' talks about this on page 62. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") dav...@rhotrading.com wrote: I apologize for posting a wron

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread Duncan Murdoch
On 1/29/2009 10:39 AM, dav...@rhotrading.com wrote: I apologize for posting a wrong opinion; I should of course have checked before posting. Henrik's examples illustrate something I had never realized before, and it really surprised me! Where can I read the technical details of this scoping aspe

Re: [R] scoping rules for 'for' [was - Re: for/if loop ]

2009-01-29 Thread davidr
I apologize for posting a wrong opinion; I should of course have checked before posting. Henrik's examples illustrate something I had never realized before, and it really surprised me! Where can I read the technical details of this scoping aspect of 'for' as it still presents some subtle puzzles f