Being naughty with R

If you sneak up to the unguarded R-session of a friend and enter this, some might soon consider exorcism:

`(` <- function(x) if(is.numeric(x)) runif(1)*x else x

In R the bracket, as in (1+2), is also a function, just as the + part of the expression is. The same is true of {}, as used in function declarations, if-clauses and for-loops. Since R is so flexible, you may well reassign these functions.

This is a great way to make enemies delightful intellectual challenge. Bonus points for entering the definition into an .Rprofile so it is not lost too easily when restarting R.

Leave a Reply

Your email address will not be published.

Please simplify: \(\int\limits_{8}^{3} 10 dx=\)