hadley/ggplot2 — Issue #377: different environments for evaluating different arguments?
Author: yihui
Created: 2012-01-30 16:33:41+00:00
State: open

This seems weird to me (`qplot()` can find the object `freq`, but cannot find `m`, so it seems the arguments `x` and `breaks` are evaluated in different environments):

```r
library(evaluate)
f = function() {
env = new.env(parent = globalenv())
evaluate("library(ggplot2)
freq <- table(as.integer(runif(1000, 1, 100)))
m <- max(freq) + 1
qplot(c(freq), breaks=0:m, log='y', xlab='Probe number')",
envir = env)
}
str(f())
## List of 5
## $ :List of 1
## ..$ src: chr "library(ggplot2)\n"
## ..- attr(*, "class")= chr "source"
## $ :List of 1
## ..$ src: chr " freq <- table(as.integer(runif(1000, 1, 100)))\n"
## ..- attr(*, "class")= chr "source"
## $ :List of 1
## ..$ src: chr " m <- max(freq) + 1\n"
## ..- attr(*, "class")= chr "source"
## $ :List of 1
## ..$ src: chr " qplot(c(freq), breaks=0:m, log='y', xlab='Probe number')"
## ..- attr(*, "class")= chr "source"
## $ :List of 2
## ..$ message: chr "object 'm' not found"
## ..$ call : language eval(expr, envir, enclos)
## ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
```

from yihui/knitr#111