[R] Assignment of structures on a given environment

Rita Ribeiro rita at liacc.up.pt
Tue Oct 16 17:40:34 CEST 2001


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"



    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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list