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

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Mar 24 19:37:05 CET 1999

On Wed, 24 Mar 1999, Athula Herath wrote:

> I wonder whether the mechanism of parsing parameters to functions has
> changed between 0.63.1 and 0.63.3? The following code yeilds different

No, but the handling of attributes has.

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

The help page for apply says


       x: the array to be used.

and your x is not an array, although R does an as.matrix for you. The
problem is that you are expecting apply to hand you a row vector labelled
by the column names of the (coerced) matrix. This is true in some versions
of R but not in others, and AFAIK is not documented to be expected. The
names of a vector are attributes, and we have been debating which
attributes should be retained on subsetting (as here).

> However, R Version
> Version 0.64.0 Unstable (February 4, 1999)
> Reports a similar behaviour to Version 0.63.1 : i.e. giving me the
> correct results. 

Yes, but that is an old snapshot: it does not do so on the March 24, 1999
version. (What is `correct' is debatable: I would suggest that your code is
incorrect if (as I think) it relies on undocumented features. (But then
most R code would be classified as incorrect!)

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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