On 4/08/2009, at 8:40 AM, rkevinbur...@charter.net wrote:

Simple question:

Why doesn't the following work? Or what 'R' rule am I missing?

tclass <-  "Testing 1 2 3"
if(tclass == "Testing 1 2 3")
{
    cat("Testing", tclass, "\n")
}
else
{
    cat(tclass, "\n")
}

I get an error 'else' is unexpected.

The segment

if(tclass == "Testing 1 2 3")
{
    cat("Testing", tclass, "\n")
}

Is syntactically complete, so that when the parser comes to the ``else'' it
finds it ``dangling'' and hence ``unexpected''.

The following wee adjustment works:

tclass <-  "Testing 1 2 3"
if(tclass == "Testing 1 2 3")
{
    cat("Testing", tclass, "\n")
} else {
    cat(tclass, "\n")
}

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@r-project.org 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.

Reply via email to