Skip to content
Prev 56899 / 63424 Next

"if" function in pure R?

Hello Alexandre,

there are two sides of your question it seems to me:

- there is no possibility to extend the R parser with new syntax. The R 
parser knows to internally "rewrite"(*) things such as

if (a>b) print(1) else print(2)

into

`if`(a>b, print(1), print(2))

The parser has a fixed set of functions that get some special treatment 
like this.

- there is possibility to implement control flow constructs thanks to 
the lazy evaluation of arguments. An example of such function is ifelse 
from base.

Best,
Stepan

(*) "rewrite" is illustrative, the exact internal working of this is not 
important for this discussion
On 27/05/2019 08:16, Alexandre Courtiol wrote: