From jmartin2003 at notamusica.com  Tue Jul 29 19:40:01 2003
From: jmartin2003 at notamusica.com (Dr. Johannes Martin)
Date: Tue Jul 29 18:39:51 2003
Subject: [Rd] cbind/rbind inconsistency with NULL parameter (PR#3585)
In-Reply-To: <Pine.LNX.4.44.0307291626460.12797-100000@gannet.stats>
Message-ID: <Pine.LNX.4.44.0307291822040.14885-100000@halef.NotaMusica.com>

Dear Professor Brian Ripley,

please excuse my inability to interpret the help page correctly.

:[help(cbind)]
:     For `cbind' (`rbind'), vectors of zero length are ignored unless
:     the result would have zero rows (columns), for S compatibility.

I guess this implies that NULL is a zero length vector, even though
	> is(NULL, "vector")
	[1] FALSE


:[help(cbind)]
:     (Zero-extent matrices do not occur in S and are not ignored in R.)

So, if neither NULL nor zero-extent matrices are ignored in R, I would
not expect the following results.
	> cbind(NULL,diag(0,0,2))
	     [,1] [,2] [,3]
	> cbind(diag(0,0,0),diag(0,0,2))
	     [,1] [,2]
Apparently, zero-extent matrices are ignored in R, or there is a
difference in the way of (not) ignoring zero-extent matrices and NULLs.

> So?  It's a documented feature.
Yes, if you know how to interpret the documentation.

Sincerely
	Johannes Martin

On Tue, 29 Jul 2003, 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@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@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
>


[Rd] cbind/rbind inconsistency with NULL parameter (PR#3585)
Dr. Johannes Martin