[From nobody Sat Mar 18 16:19:09 2006 X-Mozilla-Status2: 00000000 Message-ID: <3BCD5CE2.B22E59FC@liacc.up.pt> Date: Wed, 17 Oct 2001 11:26:42 +0100 From: Rita Ribeiro <rita@liacc.up.pt> X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en MIME-Version: 1.0 To: Robert Gentleman <rgentlem@jimmy.harvard.edu> Subject: Re: [R] Assignment of structures on a given environment References: <3BCC54F2.6A0E4D54@liacc.up.pt> <20011016124517.S6980@jimmy.harvard.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Robert Gentleman wrote: > On Tue, Oct 16, 2001 at 04:40:34PM +0100, Rita Ribeiro wrote: > > Hi, > > > > In order to avoid deep copies by passing large arguments to functions or > > > > returning values, I'm trying to do the assignment of variables in a > > given environment. The problem is when I try to assign a structure: a > > list for example. > > > > If I have: > > ind <- c("a","b") > > > > my idea is doing something like > > > > l <- alist() > > l[ind] <- as.list(c(20,40)) > > > > in a given environment. > > > > > > > > Example: > > ref <- new.env() > > (.....) > > assign("l",alist(),env=ref) > > > > > > If I do > > assign("l$a",20,env=ref) > > > > it creates me a new variable in the ref environment named "l$a" > > > This is what you asked it to do. > Environments work at the level of whole objects. I'm not sure what > it would mean for l$a to exist in ref if l doesn't exist in ref. > So, you just assign l into the environment and retrieve it from the > environment, using get. > > If you you have only one list then perhaps you do not want to put > the list in, rather just the elements. > > names <- names(l) > for(i in 1:length(l)) assign(names[i], l[[i]], env=ref) > > you then have a and b, for example, in the environment and can > extract them. > > If you have two lists, l1 and l2 and both have a's and b's as > components then you have to put in the whole list (or adopt a > naming convention). > Hi, again My problem is concerned with the fact that my list will be a list of lists which elements will be sucessively appended and defined. I want to "build" the whole list into the environment. preserving its structure (it will be useful for me to be able to manipulate the list later). More precisely, I want to do ,in a given environment, something like: l <- alist() l$first <- alist() l$first[ind] <- as.list(c(20,40)) # where ind is local vector containind the elements names l$second <- 50 So If i do > l $first $first$a [1] 20 $first$b [1] 40 $second [1] 50 and > l$first$b [1] 40 I'm searching for some alternative to solution to define this hierarchy in the designed environment, without needing to use the 'evalq' command..... Is there one? Thanks again, Rita > > One might ask whether you are sure that you need to do this? > I work on very large data sets and copying has pretty much never > been an issue. > > > > > > > So, I did: > > > > eval(l <- alist(), env=ref) > > > > but this creates the l list both on the current and on the ref > > environment. > > > > > > The alternative solution that I found out was: > > > > evalq(l<-alist(),env=ref) > > > > and then > > > > evalq(ind <-c("a","b"), env=ref) > > evalq(l[ind] <- as.list(c(20,40)), env=ref) > > > > > > I would like to know if there is another possible solution, instead of > > doing these 'evalqs' along the program code. > > > > > > Thanks, > > > > Rita > > > > > > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > > Send "info", "help", or "[un]subscribe" > > (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch > > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ > > -- > +---------------------------------------------------------------------------+ > | Robert Gentleman phone : (617) 632-5250 | > | Associate Professor fax: (617) 632-2444 | > | Department of Biostatistics office: M1B28 > | Harvard School of Public Health email: rgentlem@jimmy.dfci.harvard.edu | > +---------------------------------------------------------------------------+ > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ ]