Re: cbind is not generic as claimed, omits labels where S has them (PR#239)

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: cbind is not generic as claimed, omits labels where S has them (PR#239)
From: Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
Date: Thu 05 Aug 1999 - 23:57:27 EST


Message-ID: <x2lnbqgwjc.fsf@blueberry.kubism.ku.dk>

ripley@stats.ox.ac.uk writes:

> (1) ?cbind claims
>
> The generic functions `cbind' and `rbind' take a
> sequence of vector and/or matrix arguments and combine
> them as the columns or rows, respectively, of a matrix.
>
> Note:
>
> The method dispatching is not done via `UseMethod(..)',
> but by C-internal dispatching. Therefore, there's no
> need for, e.g., `rbind.default'.
>
> but my cbind.ts does not get called, and try the following:
>
> cbind.my <- function(...)
> {
> stop("used cbind.my")
> }
> a <- b <- 1:3
> cbind(a, b)
> class(a) <- "my"
> cbind(a, b)
> [,1] [,2]
> [1,] 1 1
> [2,] 2 2
> [3,] 3 3
>
> This is incorrect.
>
> (2) S would give
> a b
> [1,] 1 1
> [2,] 2 2
> [3,] 3 3
> (and stop on the second cbind call).
>
> and this discrepancy is hardly an improvement!
>
> Could someone who can understands the c/rbind code please sort this out.
> (It looks pretty arcane to me, and surely should not be special-casing data
> frames.)

Hmm.

(1) The docs are clearly wrong (or perhaps rather, wishful thinking)

(2) Cbind should be generic as in Splus

(3) For the labels, one needs essentially to implement deparse.level
    or face the horrors of
    eval(substitute(cbind(a,b,deparse.level=2),list(a=rnorm(10),b=rnorm(10))))

(4) The dataframe special casing seems to be an evasion. The sticky
    bit is that one needs to dispatch on *any* argument. For Splus (3.4)
    compatibility, one has to check each argument for its class
    method, and if all arguments agree - in the sense that all the
    arguments that have class methods must have the same one, dispatch
    to that method. If they disagree, print error message and try
    default method.

    Whoever wrote the code seems to have decided that things would be
    easier if one assumed that the only method for cbind was
    cbind.data.frame...

    Note that by the above logic, if you make a cbind.ts, you can't
    cbind a time series to a data frame!
 

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


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:06 EST