[Rd] cbind/rbind inconsistency with NULL parameter (PR#3585)

Tony Plate tplate at blackmesacapital.com
Wed Jul 30 10:30:09 MEST 2003


The R help for cbind/rbind states:

>      For `cbind' (`rbind'), vectors of zero length are ignored unless
>      the result would have zero rows (columns), for S compatibility.
>      (Zero-extent matrices do not occur in S and are not ignored in R.)

I presume this means the S language as defined in the Blue Book ("The ^New 
S Language", Becker Chambers & Wilks, 1988), though in a brief reading I 
couldn't find any mention of such a constraint in the sections on Matrices 
and on Arrays (pages 126 thru 135 in my copy), or any mention of such 
constraints or behavior in the descriptions of the functions cbind/rbind() 
and matrix().

FWIW, in S-plus 6.1 zero-extent matrices are allowed, and cbind/rbind do 
not seem to behave in this way (under Windows at least).

E.g.:
S6.1> matrix(nrow=0,ncol=0)
logical matrix: 0 rows, 0 columns.
S6.1> cbind(NULL, matrix(nrow=0,ncol=0))
NULL
S6.1> cbind(numeric(0), matrix(1, nrow=0,ncol=1))
NULL
S6.1>

Also, FWIW, I have argued to Insightful that cbind/rbind returning NULL 
here is a undesirable (along with other examples of inconsistent behavior 
with zero-extent matrices), and they have replied that they have logged 
these as bugs to be fixed in a future release.

-- Tony Plate

At Tuesday 04:31 PM 7/29/2003 +0100, Prof Brian Ripley wrote:
>That's as documented, on the help page.  (NULL is a zero-length argument.)
>There's even a reason given.
>
>Exactly which part of the help page did you not understand?
>
>On Tue, 29 Jul 2003 jmartin2003 at notamusica.com wrote:
>
> > R-Version: 1.7.1  (2003-06-16)
> > OS: Debian/GNU Linux
> >
> > cbind and rbind handle NULL parameters inconsistently.
> >
> > Consider:
> >   > cbind()
> >   NULL
> >   > cbind(NULL)
> >   NULL
> >
> > And:
> >   > cbind(diag(x = 1, 1, 1))
> >        [,1]
> >   [1,]    1
> >   > cbind(NULL, diag(x = 1, 1, 1))
> >        [,1]
> >   [1,]    1
> >
> > These seem to indicate that NULL parameters will be ignored in any call to
> > cbind and rbind. However:
> >
> > > cbind(NULL, diag(x = 1, 0, 1))
> >      [,1] [,2]
> >
> > I.e. if one dimension of another parameter to cbind/rbind is zero,
> > cbind/rbind will create a row/column from the NULL parameter.
> >
> > This inconsistency creates problems in the construction of matrices within
> > loops and similar constructs.
>
>So?  It's a documented feature.
>
>--
>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 272866 (PA)
>Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>
>______________________________________________
>R-devel at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list