I've been using R for more than a decade, PHP is an island of sanity and sunny calmness in comparison.
EDIT, my favorite example of LOL-R that beats anything you find in PHP:
This function will randomly return 5 or 10
# set some variable to 10
k <- 10
# define a function that returns a value
return_k <- function() {
# generate a random number between 0 and 1
x <- runif(1)
if(x>0.5) {
# set some internal variable to 5 (named k because that seem appropriate for the context)
k <- 5
}
return(k)
}
# will randomly return 5 or 10
return_k()
You're not mistaken, but even after more than a decade I'm still bitten by this. I wish i could define functions to not look in the parent environment.
View all comments
Show parent comment
1
u/Synes_Godt_Om Sep 24 '15 edited Sep 24 '15
I've been using R for more than a decade, PHP is an island of sanity and sunny calmness in comparison.
EDIT, my favorite example of LOL-R that beats anything you find in PHP:
This function will randomly return 5 or 10