[R] R multiline expression grief
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Mar 13 14:20:41 CET 2009
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 far as you intend, perhaps. note, the above snippet says:
f <- a; +b; +c
not
f <- a + b + c
> This is causing me endless problems since case f is our house style
> for breaking up expressions for readability. All our code will need to
> be rechecked as a result. Is this behaviour a bug?
clearly not. and it's hardly idiosyncratic to r. you'd have the same
behaviour in, e.g., python, though there you can explicitly demand that
the lines form a single statement by ending the first two with a
backslash. there have been similar discussions on mailing lists of a
number of programming/scripting languages.
> If not, is it
> possible to get R to generate a warning that several lines of an
> expression are potentially being ignored,
they're not ignored! you demand to compute +b and +c, and it's
certainly done. (i don't think r is smart enough to optimize these away).
> perhaps by turning on a
> strict mode which requires the semi-colons?
>
that's an idea, but the proposed solution would have to be optional to
avoid annoying those who don't like semiquotes in r code.
vQ
More information about the R-help
mailing list