Skip to content

Commit c786526

Browse files
author
hornik
committed
Have NCOL(NULL) return 0 instead of 1.
git-svn-id: https://svn.r-project.org/R/trunk@85704 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 36b76eb commit c786526

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@
226226
convention once Unicode restricted the number of Unicode points
227227
to \eqn{2{^31} - 1}{2^31 - 1} and so will never need more than 6
228228
digits.)
229+
230+
\item \code{NCOL(NULL)} now returns 0 instead of 1, for
231+
consistency with \code{cbind()}.
229232
}
230233
}
231234

src/library/base/R/matrix.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ nrow <- function(x) dim(x)[1L]
3030
ncol <- function(x) dim(x)[2L]
3131

3232
NROW <- function(x) if(length(d <- dim(x))) d[1L] else length(x)
33-
NCOL <- function(x) if(length(d <- dim(x)) > 1L) d[2L] else 1L
33+
NCOL <- function(x)
34+
if(is.null(x)) 0L else if(length(d <- dim(x)) > 1L) d[2L] else 1L
3435

3536
rownames <- function(x, do.NULL = TRUE, prefix = "row")
3637
{

src/library/base/man/nrow.Rd

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ NROW(1:12) # 12, the length() of the vector
5252
## and so does cbind() :
5353
dim(as.matrix(numeric())) # 0 1
5454
dim( cbind(numeric())) # ditto
55-
## consequently, NCOL(.) gives 1, too :
56-
NCOL(numeric()) # 1 and hence
57-
NCOL(NULL) # 1
55+
NCOL(numeric()) # 1
56+
## However, as.matrix(NULL) fails and cbind(NULL) gives NULL, hence for
57+
## consistency:
58+
NCOL(NULL) # 0
59+
## (This gave 1 in R < 4.4.0.)
5860
}
5961
\keyword{array}

src/library/profile/Common.R

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,3 @@ local({
128128

129129
makeActiveBinding(".Library.site", slfun, globalenv())
130130
})
131-
132-
if(isTRUE(as.logical(Sys.getenv("_R_NCOL_NULL_IS_ZERO_",
133-
"FALSE")))) {
134-
NCOL <- function(x)
135-
if(is.null(x)) 0L
136-
else if(length(d <- dim(x)) > 1L) d[2L]
137-
else 1L
138-
}

0 commit comments

Comments
 (0)