[R] if/else statement without curly brackets gives a problem

Ery Arias-Castro eariasca at ucsd.edu
Sun Jan 22 03:56:25 CET 2012


Hello,

This example seems strange to me:

> if (2 > 3) print('Yes'); else print('No')
Error: unexpected 'else' in " else"

> {if (2 > 3) print('Yes'); else print('No')}
Error: unexpected 'else' in "{if (2 > 3) print('Yes'); else"

> {
+ 	if (2 > 3) print('no')
+ 	else print('yes')
+ }
[1] "yes"


Any enlightening comments?

Ery



More information about the R-help mailing list