[R] variable capture in apply

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Oct 28 11:42:29 CET 1998


Kjetil Halvorsen <khal at alumni.uv.es> writes:

> The following example is from `S Poetry', page 78-79.  It
> seems to indicate some error in lapply, sapply, 
> or both? [It does, and below the solution is given also.]
> 
....
> > sapply( seq(along=jjalist), function(i,x,y) 
> +    {x[[i]] %*% y[[i]]}, x=jjalist, y=jjblist)
....
[short summary: sapply() calls lapply() which has its first argument
 called "x" matching the "x=jjalist" via "..." and things go crazy]

Yup. The *apply() functions should be consistent in the argument
naming for this reason. Of course, that doesn't guard against people
using X as an argument name in their functions, but it'll be a bit
more obvious what goes wrong. Fixed for 0.63.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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