Damn scoping in R
Ok, R is very well-considered in certain respects, but there are also some things annoying me… This time it’s scoping…
Let’s have a look to the following code:
First it looks damn unspectacular. But wait, whats that:
Taking a closer look to the function shows that the returned value is randomly chosen from local ( runif(1) > .5
) or global scope ( runif(1) <= .5
). So you can’t expect a result from this function. Nasty, especially while debugging external code, isn’t it? :-)
So again my advise: Think about such specific features! This won’t happen in any sensible language…
Leave a comment
There are multiple options to leave a comment: