[R] if block and brackets

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Mar 25 07:28:09 CET 2004


On Wed, 24 Mar 2004, Fred J. wrote:

> Hello
> the maunal states "When the if statement is not in a
> block the else, if present, must appear on the same
> line as statement1. Otherwise the new line at the end
> of statement1 yields a syntactically complete
> statement that is evaluated."
> well, what is wrong with this if structure? I am
> getting an error on the line where "else" is

The else is inside a { } block.

If you use a good editor and proper indentation such errors will be 
obvious to you.

> 
> thanks
> 
>   if (exists("f")){
>     dt <- read.csv(file.path(d,f),header=F)#data frame
>     builddl(dt,f)
>   else
>     for (i in dir(d)){
>       dt <-
> read.csv(file.path("c:/data",i),header=F)#data frame
>       an <- sub("([^.]+)(\\..+)","\\1", i))
>     builddl(dt,an)
>   }
> }
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list