Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created January 17, 2013 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyiacono/4553792 to your computer and use it in GitHub Desktop.
Save jeffreyiacono/4553792 to your computer and use it in GitHub Desktop.
demonstration of R's lexical scoping
> y <- 10
> f <- function(x) {
y <- 2
y^2 + g(x)
}
> g <- function(x) {
x * y
}
> f(3)
[1] 34
> ls(environment(g))
[1] "f" "g" "y"
> get("y", environment(g))
[1] 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment