From Thomas.Petzoldt at tu-dresden.de  Mon Jan 21 18:06:47 2008
From: Thomas.Petzoldt at tu-dresden.de (Thomas Petzoldt)
Date: Mon, 21 Jan 2008 18:06:47 +0100
Subject: [Rd] experiments with slot functions and possible problems NOTE
In-Reply-To: <971536df0801210849m3c578513n40b00de45486552b@mail.gmail.com>
References: <47949E59.9070603@tu-dresden.de>
	<971536df0801210849m3c578513n40b00de45486552b@mail.gmail.com>
Message-ID: <4794D127.7030708@tu-dresden.de>

Hi Gabor,

nice to see you on this thread.
As you see, I'm back with my old problem.

Gabor Grothendieck wrote:
 > If the intention is to place fList's contents in the global
 > environment
 > then you need to specify that in addtoenv or else it assumes
 > the parent environment.

No, it was the intention to keep the global environment as clean as 
possible and to use local data structures instead.

 >> flistA <- list(foo = function () 1:10, bar = function() log(foo()))
 >> makefun <- function(fList) addtoenv(fList, .GlobalEnv)
 >> makefun(flistA)
 > $foo
 > function() {
 >    1:10
 >   }
 >
 > $bar
 > function() {
 >     log(foo())
 >   }
 >
 >> foo()
 >  [1]  1  2  3  4  5  6  7  8  9 10
 >> bar()
 >  [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 
1.9459101
 >  [8] 2.0794415 2.1972246 2.3025851
 >
 > Note that this takes advantage of the fact that in your example
 > flistA was
 > defined in the global environment in the first place.  Had that not
 > been the
 > case we would have had to reset the environment of bar so that it
 > could find foo.
 >
 > By the way.  What about just attach(flistA) ?

You are right, attach works. I used it in another package instead of 
addtoenv, but it introduced new problems, even if I use it the following 
way:

attach(flist)
on.exit(detach(flist))

[...]

Additionally, I've never seen attach in another package.

Thomas P.



[Rd] experiments with slot functions and possible problems NOTE
Thomas Petzoldt