Skip to content

Commit

Permalink
b1 updated
Browse files Browse the repository at this point in the history
  • Loading branch information
renkun-ken committed Apr 2, 2014
1 parent 0bf3d38 commit 8d3fb22
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/b1.r-language-mechanism.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ e1 <- as.environment(l1)
e2 <- new.env()
e2$a <- 0
e2$b <- 0
e3 <- list2env(l1)

ls.str(l1)
ls.str(e1)
ls.str(e2)
ls.str(e3)

fun <- function(x) {
x$a <- x$a+1
Expand All @@ -67,6 +69,10 @@ ls.str(e1)
fun(e2)
ls.str(e2)

fun(e3)
ls.str(e3)


get("a",envir = e1)
get("b",envir = e2)

Expand Down Expand Up @@ -117,8 +123,15 @@ eval(e2,env)
env <- as.environment(list(x=20))
eval(e2,env)

# http://stackoverflow.com/questions/22805816/what-is-the-mechanism-that-makes-work-when-defined-by-in-empty-environment

env <- as.environment(list(x=20,`+`=function(a,b) {a+b}))
eval(e2,env)

env <- list2env(list(x=20))
eval(e2,env)

e3 <- parse(text="x <- rnorm(100)")
eval(e3)

# http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/

0 comments on commit 8d3fb22

Please sign in to comment.