[R] syntax rules
Hiroyuki Kawakatsu
kawa at aris.ss.uci.edu
Tue Feb 25 16:19:03 CET 2003
hi,
i lost half a day trying to figure out how r is parsing statements
in multiple lines. can someone explain (or direct me to documentation) the
following. consider the following statements in a program file, say
foo.r:
a <- 1 +
2;
b <- {1
+ 2};
{c <- 1
+ 2};
d <- c(1,
2);
if i do source("foo.r"), i get a=3, b=2, c=1, d={1,2}.
according to the r language definition p.11, section 3.2, it says
"A semicolon always indicates the end of a statement while a new line
'may' indicate the end of a statement. If the current statement is not
syntactically complete new lines are simply ignored by the evaluator."
then, a and d are evaluated as expected since the first lines are not
syntactically complete. however, why does b evaluate to 2 and c to 1?
(it appears to evaluate differently if i do this interactively.)
i got the idea of using curly braces from p.12 of the language definition.
is there a way to keep adding terms with a line beginning with a plus sign
(notationally, i don't like plus symbols hanging at the end of a line...)?
h.
--------------------------------------------------------------------
Time series regression studies give no sign of converging toward the
truth. (Phillip Cagan)
More information about the R-help
mailing list