No. Once the function is wrapped in with(env, ...) then variable.name is out of scope.

The problem here is that testthat defaults the environment to be parent.env(global.env()). From testthat source code:

we use as enclosure of the new env the parent of globalenv() which
is normally the first loaded package in the search path so that
tests are isolated from the global but still can find their needed
functions such as the testthat ones 

When get() is called, it normally searches enclosing environments, but in the test framework the global environment is enclosed by the test environment, so get doesn't find the global variables.

with(env, ...) moves into the global environment, but the local variable name is in the enclosing environment. with() does not search the enclosing environments so it does't work.

Kenton White

On Dec 9, 2013, at 8:17 PM, Kirill Müller <notifications@github.com> wrote:

> In tests/3.R:
> 
> > @@ -12,12 +18,12 @@ variable.name <- ProjectTemplate:::clean.variable.name('example_01')
> >  
> >  ProjectTemplate:::csv.reader(data.file, filename, variable.name)
> >  
> > -expect_that(exists(variable.name), is_true())
> > -expect_that(names(get(variable.name)), equals(c('N', 'Prime')))
> > -expect_that(nrow(get(variable.name)), equals(5))
> > -expect_that(ncol(get(variable.name)), equals(2))
> > -expect_that(get(variable.name)[5, 2], equals(11))
> > -rm(example.01)
> > +expect_that(exists(variable.name, envir = env), is_true())
> Couldn't we also use with(env, ...) here?
> 
> —
> Reply to this email directly or view it on GitHub.
>