##------------------------------------------------------------------------## ## Script for web appendix on frames, environments, and scope ## ## An R and S-PLUS Companion to Applied Regression ## ## John Fox ## ## Sage Publications, 2002 ## ##------------------------------------------------------------------------## f <- function (x) x + a a <- 10 x <- 5 f(2) f<- function (x) { a <- 5 g(x) } g <- function(y) y + a f(2) f <- function (x) { a <- 5 g <- function (y) y + a g(x) } f(2) f <- function (x) { a <- 5 g <- function (y, b) y + b g(x, a) } f(2) make.power <- function(power){ # works only in R function(x) x^power } square <- make.power(2) square square(4) cuberoot <- make.power(1/3) cuberoot cuberoot(64)