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:
#
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
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:
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
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
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
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,
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:
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:
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
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
11 matches
Mail list logo