October 2012
Beginner to intermediate
721 pages
21h 38m
English
In the last few sections, most examples of objects were objects that stored data: vectors, lists, and other data structures. However, everything in R is an object: functions, symbols, and even R expressions.
For example, function names in R are really symbol objects that point to function objects. (That relationship is, in turn, stored in an environment object.) You can assign a symbol to refer to a numeric object and then change the symbol to refer to a function:
> x <- 1 > x [1] 1 > x(2) Error: could not find function "x" > x <- function(i) i^2 > x function(i) i^2 > x(2) [1] 4
You can even use R code to construct new functions. If you really wanted to, you could write a function that modifies its own definition.
Read now
Unlock full access