Re: [R] Got "Unexpected ELSE error"

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Wed, 20 Jun 2007 11:58:33 +0200

the problem is that you start `else' on a new line; check the following two solutions:

if ( a ) {

    cat("TRUE", "\n")
} else {

    cat("FALSE", "\n")
}

# or

{
if ( a )
{

    cat("TRUE", "\n")
}
else
{

    cat("FALSE", "\n")
}
}

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm



> Dear R-users,
>
> I have a problem with the IF-ELSE syntax.
> Please look at the folllowing code and tell me what's wrong:
>
> a <- TRUE
> if ( a )
> {
> cat("TRUE","\n")
> }
> else
> {
> cat("FALSE","\n")
> }
>
> If I try to execute with R I get:
> Error: syntax error, unexpected ELSE in "else"
> The strange thing is either "cat" instructions are executed!!
>
> My system is: Fedora Core 6 x86_64 + R 2.5.0 (rpm)
>
> Thank you very much in advance!!!!
>
> Regards,
>
> -- Marco
>
> ______________________________________________
> 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.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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. Received on Wed 20 Jun 2007 - 10:13:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jun 2007 - 11:32:14 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.