[R] R multiline expression grief

2009-03-13 Thread Paul Suckling
Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: #

Re: [R] R multiline expression grief

2009-03-13 Thread jim holtman
This is a perfectly legal expression: f - a + b + c; Type it in a the console, and it will assign a to f and then print out the values of b and c. In parsing 'f - a' that is a complete expression. You may be confused since you think that semicolons terminate an expression; that is not

Re: [R] R multiline expression grief

2009-03-13 Thread Thomas Lumley
On Fri, 13 Mar 2009, Paul Suckling wrote: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1:

Re: [R] R multiline expression grief

2009-03-13 Thread Wacek Kusnierczyk
Paul Suckling wrote: ... # R-script... r_parse_error - function () { ... f - a + b + c; } ... f 1 As far as I am concerned f should have the value 3. as

Re: [R] R multiline expression grief

2009-03-13 Thread Paul Suckling
I get it. Thanks everyone for the feedback. Now that I understand how it works, my comment would be that this system is dangerous since it makes it difficult to read the code and easy to make errors when typing it. I recognise that this is something so fundamental that it is unlikely to be

Re: [R] R multiline expression grief

2009-03-13 Thread Wacek Kusnierczyk
jim holtman wrote: if (1 == 1) {print (TRUE) + } else {print (FALSE)} [1] TRUE so the parse knows that the initial 'if' is not complete on the single line. ... and likewise the original code could be rewritten as f - { a + b + c } vQ

Re: [R] R multiline expression grief

2009-03-13 Thread Gabor Grothendieck
If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a standard way. See Rtidy.bat in the batchfiles distribution for the reformatting part: http://batchfiles.googlecode.com On Fri,

Re: [R] R multiline expression grief

2009-03-13 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a standard way. See Rtidy.bat in the batchfiles distribution for the reformatting part:

Re: [R] R multiline expression grief

2009-03-13 Thread Ted Harding
On 13-Mar-09 12:55:35, Paul Suckling wrote: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1:

Re: [R] R multiline expression grief

2009-03-13 Thread Gabor Grothendieck
On Fri, Mar 13, 2009 at 10:11 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote: If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a

Re: [R] R multiline expression grief

2009-03-13 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: On Fri, Mar 13, 2009 at 10:11 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote: If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then