[R] Putting an index explicitly into function code --- a curiosity.

Rolf Turner rolf.turner at xtra.co.nz
Sat Jan 7 23:29:23 CET 2012


On 08/01/12 04:38, Gabor Grothendieck wrote:


<SNIP>

> These two variations without bquote and the third which just replaces
> for with while all (that I had previously posted) do work:
>
> # 1
> junk<- vector("list",4)
> for(i in 1:4) {
> 	junk[[i]]<- eval(substitute(function(x) { 42 + i * x }, list(i = i)))
> }
> junk
<SNIP>

Dang!  I had tried using "substitute" before trying "bquote", but hadn't
at that time figured out that I needed to "eval()" the result in order to
get a function rather than a call.  Twigged to the need to use "eval()"
while fiddling about with "bquote", and then never went back to
"substitute".

The fact that I don't really understand any of this stuff and am basically
groping around in the dark, hammering and hoping, doesn't make it
any easier! :-)

     cheers,

         Rolf



More information about the R-help mailing list