[Rd] How do you construct a function from a list?
Duncan Murdoch
dmurdoch@pair.com
Tue, 21 Nov 2000 14:01:59 GMT
I'm trying to get a data.restore function to work on functions. One
thing I can't figure out: how do you construct a function from it's
component parts?
For example, I can construct a for loop as
forloop <-
as.call(list(as.name('for'),as.name('i'),1,as.call(list(as.name('junk')))))
which results in
for (i in 1) junk()
But how do I put that in a function? For example, I'd like the
function
function() for (i in 1) junk()
but as.function(list(forloop)) results in
function ()
list(for (i in 1) junk())
which returns the for loop in a list, it doesn't execute it. How do I
construct the function?
(This might be a bug in as.function, because
as.function(c(alist(a=,b=2),forloop))
returns the expected function
function (a, b = 2)
for (i in 1) junk()
It's just that I can't seem to find a way to do it when there are no
arguments.)
Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._