Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

describe magical nature of functions? #5

Open
tdsmith opened this issue Apr 14, 2013 · 1 comment
Open

describe magical nature of functions? #5

tdsmith opened this issue Apr 14, 2013 · 1 comment

Comments

@tdsmith
Copy link
Owner

tdsmith commented Apr 14, 2013

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

dwinsemius commented Oct 26, 2019

> 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants