Re: [R] new line between '}' and 'else' in function body

2009-04-03 Thread Wacek Kusnierczyk
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

Re: [R] new line between '}' and 'else' in function body

2009-04-03 Thread Yihui Xie
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"

Re: [R] new line between '}' and 'else' in function body

2009-04-02 Thread Romain Francois
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

[R] new line between '}' and 'else' in function body

2009-04-02 Thread Yihui Xie
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