Message-ID: <Pine.A41.4.33.0107281433530.98316-100000@homer10.u.washington.edu>
Date: 2001-07-28T21:43:25Z
From: Thomas Lumley
Subject: style question: returning multiple arguments - structure orlist
In-Reply-To: <x2itgcoihn.fsf@blueberry.kubism.ku.dk>
On 28 Jul 2001, Peter Dalgaard BSA wrote:
> A little summer exercise: Can one write a list assignment function,
> i.e. "list<-" so that
>
> list(a,b,c) <- f()
>
> would be equivalent to
>
> r <- f()
> a <- r[[1]]
> b <- r[[2]]
> c <- r[[3]]
>
> Even better, do something useful with named list elements. (And what
> are the odds of finding that this is really an exercise hidden
> somewhere in a book by Venables and Ripley?)
I think you'll find that the first argument of an assignment function has
to exist already -- the function is passed the evaluated first argument.
This means it isn't quite true that
a<-"foo<-"(a,value)
is the same as
foo(a)<-value
eg
> "foo<-"<-function(x,value){list(substitute(x),value)}
> foo(a)<-4
Error: Object "a" not found
> "foo<-"(a,1)
[[1]]
a
[[2]]
[1] 1
> a<-1
> foo(a)<-4
> a
[[1]]
*tmp*
[[2]]
[1] 4
If this is correct, then you can't really write "list<-"
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._