10.3 Important to remember
- R has First-class functions (can be created with
function()
and<-
)
R functions are objects in their own right, a language property often called “first-class functions”
– Section 6.2.3
- Functions capture (enclose) environment in which they are created
f <- function(x) function(y) x + y
fn_env(f) # The function f()
#> <environment: R_GlobalEnv>
fn_env(f()) # The function created by f()
#> <environment: 0x560e54f153b8>
- Functions create a new environment on each run