Or you can use with:

> a <- new.env()
> with(a, b <- function(x) x )
> a$b
function(x) x
<environment: 0x0000000006e9e0b8>




On Wed, Aug 28, 2013 at 3:45 PM, ivo welch <ivo.welch@gmail.com> wrote:

> duh!
>
>
> ----
> Ivo Welch (ivo.welch@gmail.com)
> http://www.ivo-welch.info/
> J. Fred Weston Professor of Finance
> Anderson School at UCLA, C519
> Director, UCLA Anderson Fink Center for Finance and Investments
> Free Finance Textbook, http://book.ivo-welch.info/
> Editor, Critical Finance Review, http://www.critical-finance-review.org/
>
>
>
> On Wed, Aug 28, 2013 at 2:42 PM, Hadley Wickham <h.wickham@gmail.com>
> wrote:
>
> > On Wed, Aug 28, 2013 at 4:32 PM, ivo welch <ivo.welch@anderson.ucla.edu>
> > wrote:
> > > is it possible to temporarily change the destination environment where
> > > objects are written to?  I am thinking
> > >
> > >   a <- new.env()
> > >   attach(a)
> > >   ### run some code, such as...
> > >   b <- function(x) x
> > >   detach(a)
> > >   a$b
> > >
> > > obviously, this is wrong.  attach() only attaches for read access.  I
> > could
> > > copy the globalenv, run my code, see what objects have been changed
> > (how?),
> > > move the changed and new functions into my a environment, and then
> > restore
> > > globalenv.  or is this already done somewhere else?
> >
> > within?
> >
> > Or just:
> >
> > evalq({
> >  b <- function(x) x
> > }, a)
> >
> > Hadley
> >
> > --
> > Chief Scientist, RStudio
> > http://had.co.nz/
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com

	[[alternative HTML version deleted]]

