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

2009-01-30 Thread Patrick Burns
'The R Inferno' page 36. 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) SnowManPaddington wrote: Hi ya, thanks a lot everyone!! I changed rr:ii-1 to rr:(ii-1) and the code works!!! I finally get

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

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

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 wrong

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')

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); for (ii in

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: snip 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 unless

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

2009-01-29 Thread davidr
The lines below made me understand clearly. Maybe they are already in some documentation, but if not, it might help others to avoid my misunderstanding. Thanks to all for the clarifications. -- David -Original Message- From: Duncan Murdoch [mailto:murd...@stats.uwo.ca] Sent: Thursday,

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

2009-01-29 Thread SnowManPaddington
Hi ya, thanks a lot everyone!! I changed rr:ii-1 to rr:(ii-1) and the code works!!! I finally get some estimates from the optimization function (i am doing a logit model with 2 segments). Thanks thanks!!! I didn't realize rr:(ii-1) and rr:ii-1 would make such a big difference, especially because

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 h...@stat.berkeley.edu 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