you can always wrap the whole if/else statement into innocent braces or
parentheses, as in
y = {
if (x) 1
else 2 }
y = (
if (x) 1
else 2 )
it doesn't have to be a function, and there is no need for the
assignment either -- you just need to tell the parser that
Thanks, Romain! So I think, for consistency, the following result
> deparse(parse(text = '
+ f = function(x) {
+if (x) {
+1
+} # a new line here!
+else {
+2
+}
+ }
+ ')
+ )
[1] "structure(expression(f = function(x) {" "if (x) {"
[3] "1"
Hi,
That's because the parser knows how to deal with that stuff. However,
when you type the same if/else at the command line, it will be parsed
line by line, and the evaluator will not wait for the else to evaluate
the if. Try to copy and paste your if/else to the command line.
Romain
Yihu
Hi list members,
?"else" tells us
In particular, you should not have a newline between '}' and
'else' to avoid a syntax error in entering a 'if ... else'
construct at the keyboard or via 'source'.
but there's no syntax error when you break the line between "}" and
"else" in a func
4 matches
Mail list logo