[R] Change of parsing parameters to functions between 0.63.1 and 0.63.3 ?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Mar 24 19:09:26 CET 1999


Athula Herath <Athula.Herath at ogs.co.uk> writes:

> Hi,
> 
> 
> I wonder whether the mechanism of parsing parameters to functions has
> changed between 0.63.1 and 0.63.3? The following code yeils different
> results in R 0.63.1 (Version 0.63.1  (Dec 5, 1998)) and R 0.63.3. 
> 
> cave<-function(x,a,b)
> {
> 	return(c(mean(x[a],na.rm=T),mean(x[b],na.rm=T)))
> }
> datx <- data.frame(rbind(c(1,2,3,4),c(4,5,6,7)))
> names(datx)<-c("A","B","C","D")
> f1<-c("A","C")
> f2<-c("B","D")
> t1<-apply(datx,1,cave,f1,f2)

Yep. Error was that element names were not passed on to the FUN in
apply() in the vector case. The following patch (against 0.63.x
snapshot or 0.64 unstable) seems to fix it:
 

*** /tmp/T0a0058J	Thu Mar 25 05:51:46 1999
--- apply.R	Thu Mar 25 05:51:46 1999
***************
*** 29,35 ****
  
      ans <- vector("list", d2)
      if((i.vec <- length(d.call) < 2)) # vector
! 	for(i in 1:d2) ans[[i]] <- FUN(newX[,i], ...)
      else
  	for(i in 1:d2) ans[[i]] <- FUN(array(newX[,i], d.call, dn.call), ...)
  
--- 29,39 ----
  
      ans <- vector("list", d2)
      if((i.vec <- length(d.call) < 2)) # vector
! 	for(i in 1:d2){
! 	    xi<-newX[,i]
! 	    names(xi)<-dn.call[[1]]
! 	    ans[[i]] <- FUN(xi, ...)
! 	}
      else
  	for(i in 1:d2) ans[[i]] <- FUN(array(newX[,i], d.call, dn.call), ...)
 

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