> From: Hiroyuki Kawakatsu [mailto:kawa at aris.ss.uci.edu]
>
> 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};
The first line is not a complete statement because there's no enclosing }.
Thus b gets assign the value of the statement enclosed in {}.
> {c <- 1
> + 2};
The first line here *is* a complete statement. The entire { } expression
gets the value of the the last line, namely "+2". Try:
> junk <- { b <- 1
+ + 2};> b
[1] 1> junk
[1] 2
Andy
> 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)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
------------------------------------------------------------------------------