[R] Assignment of structures on a given environment

David A Richmond richmond at saintmarys.edu
Wed Oct 17 00:39:21 CEST 2001


I was having trouble with a similar issue recently, until I was informed
that arguments to functions aren't copied unless they're altered. So I can
pass a large matrix through a routine with as many sublevels as i need and
the matrix won't be recreated everytime I pass it to another function. Is
this the problem you're trying to avoid?

dave


On Tue, 16 Oct 2001, 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"
> 
> 
> 
>     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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|David Richmond                It works on a          |      
+ Dept. of Sociology          complex scientific      + 
|Saint Mary's College          principle, known as    |  
+ Notre Dame, IN 46556               "pot luck."      +
|219-284-4517                    - The Doctor         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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