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 the input hasn't ended. that's a matter of taste, but i find { if (x) 1 else 2 } more readable than something like if (x) { 1 } else 2 vQ Yihui Xie wrote: > 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" " }" > [5] " else {" " 2" > [7] " }" "}), srcfile = > <environment>)" > > should be > > [1] "structure(expression(f = function(x) {" " if (x) {" > [3] " 1" " } else {" > [5] " 2" " }" > [7] "}), srcfile = <environment>)" > > instead. > > Regards, > Yihui > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.