Re: [R] A statement over multiple lines (i.e. the ... feature in Matlab)

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Thu 05 Oct 2006 - 08:49:52 GMT

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@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

______________________________________________
R-help@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.
Received on Thu Oct 05 18:53:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 05 Oct 2006 - 09:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.