[R] Weird feature when creating function lists with apply

Uffe Høgsbro Thygesen uht at dfu.min.dk
Wed Oct 10 12:49:05 CEST 2001


Thanks, Peter and Prof. Ripley, for your helpful replies.

Referring to Prof. Ripley's reply, when I do

f3 <- function(a) substitute(function(x) a*x, list(a = a))
f <- lapply(1:4, f3)[[1]]

then f is not a function:

> is.function(f)
[1] FALSE

but 

> is.function(eval(f))
[1] TRUE

Consistently, if I do

f4 <- function(a) eval(substitute(function(x) a*x, list(a = a)))
g <- lapply(1:4, f4)[[1]]

then g is indeed a function:

> is.function(g)
[1] TRUE

I do still not understand what f is, then, except something that evaluates
to a function. My conclusion is that I need to start my head, too, and
understand this lazy evaluation.

Thanks again. Cheers,

Uffe



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Uffe H. Thygesen, M.Sc.&Eng., Ph.D.
Danish Institute of Fisheries Research
http://www.dfu.min.dk


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