[R] A statement over multiple lines (i.e. the ... feature in Matlab)
Robin Hankin
r.hankin at noc.soton.ac.uk
Thu Oct 5 10:49:52 CEST 2006
On 5 Oct 2006, at 09:34, Bjørn-Helge Mevik wrote:
> Robin Hankin wrote:
>
>> For the line breaking, R deals with incomplete lines by not
>> executing the statement until you finish it.
>
> Beware, however, that syntactically valid lines do get executed
> immediately (at least at the prompt).
yes, you're quite right. Your observation
leads to my number 1 gotcha:
if(1<2) print("1<2")
else
print("1>2")
which (properly) returns an error because the first line is
syntactically
complete, so the "else" statement is processed ab initio.
So now I always always always always type
if(1<2){
print("1<2")
} else {
print("1>2")
}
if by some chance I ignore emacs/ESS's indentation telling me I've
forgotten
a brace.
best wishes
rksh
> So
>
> 1 + 2
> - 3
>
> will be interpreted as two commands (returning 3 and -3,
> respectively), while
>
> 1 + 2 -
> 3
>
> will be interpreted as a single command (returnig 0).
>
> --
> Bjørn-Helge Mevik
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
More information about the R-help
mailing list