[R] if confusion
Rolf Turner
r.turner at auckland.ac.nz
Mon Aug 3 22:51:20 CEST 2009
On 4/08/2009, at 8:40 AM, rkevinburton at 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}}
More information about the R-help
mailing list