tdsmith / aRrgh

A newcomer's (angry) guide to data types in R
Other
307 stars 14 forks source link

describe magical nature of functions? #5

Open tdsmith opened 11 years ago

tdsmith commented 11 years ago
 +* 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

dwinsemius commented 4 years ago
> 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