This is certainly worth discussing, but there's always a heavy burden of back-compatibility; how much better would it be for NCOL and NROW to both return zero, vs. the amount of old code that would be broken?

Furthermore, the reason for this behaviour is justified as consistency with the behaviour of as.matrix() and cbind() for zero-length vectors, from ?NCOL:

     ## as.matrix() produces 1-column matrices from 0-length vectors,
     ## and so does cbind() :

(of course you could argue that this behaviour should be changed as well ...)


On 2023-09-23 3:41 p.m., Simone Giannerini wrote:
I know it's documented and I know there are other ways to guard
against this behaviour, once you know about this.
The point is whether it might be worth it to make NCOL and NROW return
the same value on NULL and make R more consistent/intuitive and
possibly less error prone.

Regards,

Simone

On Sat, Sep 23, 2023 at 7:50 PM Duncan Murdoch <murdoch.dun...@gmail.com> wrote:

It's been documented for a long time that NCOL(NULL) is 1.  What
particular problems did you have in mind?  There might be other ways to
guard against them.

Duncan Murdoch

On 23/09/2023 1:43 p.m., Simone Giannerini wrote:
Dear list,

I do not know what would be the 'correct' answer to the following but
I think that they should return the same value to avoid potential
problems and hard to debug errors.

Regards,

Simone
---------------------------------------

NCOL(NULL)
[1] 1

NROW(NULL)
[1] 0

sessionInfo()
R version 4.3.1 RC (2023-06-08 r84523 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=Italian_Italy.utf8  LC_CTYPE=Italian_Italy.utf8
[3] LC_MONETARY=Italian_Italy.utf8 LC_NUMERIC=C
[5] LC_TIME=Italian_Italy.utf8

time zone: Europe/Rome
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.3.1





______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to