Skip to content

Instantly share code, notes, and snippets.

@JWiley
Created July 7, 2012 10:14
Show Gist options
  • Save JWiley/3065740 to your computer and use it in GitHub Desktop.
Save JWiley/3065740 to your computer and use it in GitHub Desktop.
Scoping Fun in R
## In the end, what is the twelth column of 'dat', a, and b?
## why does the local() not matter in thirteen?
a <- 10
b <- 10
dat <- local(
data.frame(
first = b,
second = a <- 0 -> b,
third = a <- rnorm(10, mean = a),
fourth = a / 2,
fifth = a <- rnorm(10, mean = a <- b),
sixth = a * rnorm(10, b) -> a,
seventh = b <- a^2,
eigth = {rm(b); 1:10},
ninth = a * b,
tenth = b <<- a -> b,
eleventh = {rm(a); b <- 10:1}, twelth = a,
thirteenth = local(a <<- b -> a)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment