Message-ID: <3F252BF8-F7A2-40C1-8FE5-425CC4EE748A@auckland.ac.nz>
Date: 2009-08-03T20:51:20Z
From: Rolf Turner
Subject: if confusion
In-Reply-To: <20090803164039.306IZ.2798143.root@mp05>
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}}