aRrgh icon indicating copy to clipboard operation
aRrgh copied to clipboard

describe magical nature of functions?

Open tdsmith opened this issue 11 years ago • 1 comments

 +* 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

tdsmith avatar Apr 14 '13 01:04 tdsmith

> 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

dwinsemius avatar Oct 26 '19 22:10 dwinsemius