aRrgh
aRrgh copied to clipboard
describe magical nature of functions?
+* Deep down, everything in R is a function, though. R is pretty scheme-y and LISP-y under the hood. One can write `"+"(2, 3)` to call the `+` operator on numbers 2 and 3, for example! Even crazier, `"for"( i, 1:10, print(i^2) )` shows that the keywords are functions themselves.
from cdrv
> is.function(`+`)
[1] TRUE
> is.function(`for`)
[1] TRUE
And let's not forget the all important:
> is.function(`[`)
[1] TRUE
> is.function(`[<-`)
[1] TRUE
You still need to use a "naked" <-
to acheive lasting changes:
> a = c(1,2,3,4)
> `[<-`(a, 2, 10)
[1] 1 10 3 4
> a
[1] 1 2 3 4
> a <- `[<-`(a, 2, 10)
> a
[1] 1 10 3 4