HenrikBengtsson / matrixStats

R package: Methods that Apply to Rows and Columns of Matrices (and to Vectors)
https://cran.r-project.org/package=matrixStats
202 stars 33 forks source link

CRAN: Errors on R-devel #241

Closed HenrikBengtsson closed 9 months ago

HenrikBengtsson commented 9 months ago
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Thu, Oct 26, 2023 at 12:07 AM
Subject: CRAN package matrixStats
To: <henrikb@braju.com>
Cc: <CRAN@r-project.org>

Dear maintainer,

Please see the problems shown on
<https://cran.r-project.org/web/checks/check_results_matrixStats.html>.

Please correct before 2023-11-09 to safely retain your package on CRAN.

The CRAN Team

There are several errors on https://cran.r-project.org/web/checks/check_results_matrixStats.html. All of them appears to be of kind:

     Error in validateIndicesTestMatrix(x, rows, cols, ...
HenrikBengtsson commented 9 months ago

I can reproduce this with a recent R-devel version. To get going, here's how to reproduce it without involving R CMD check:

> source("tests/rowCumMinMaxs.R", chdir=TRUE)
add_na = FALSE
mode: logical
 logi [1:10, 1:5] FALSE TRUE TRUE TRUE TRUE TRUE ...
Error: r1 and r0 are not equal:
  Attributes: < Length mismatch: comparison on first 1 components >
In addition: Warning messages:
1: useNames = NA is deprecated. Instead, specify either useNames = TRUE or useNames = FALSE. 
2: useNames = NA is deprecated. Instead, specify either useNames = TRUE or useNames = FALSE. 

This is because:

> str(r0)
 int [1:10, 1:5] 0 1 1 1 1 1 1 1 1 1 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:10] "a" "b" "c" "d" ...
  ..$ : chr [1:5] "A" "B" "C" "D" ...
> str(r1)
 int [1:10, 1:5] 0 1 1 1 1 1 1 1 1 1 ...
HenrikBengtsson commented 9 months ago

This is because in R-devel dim<-() now preserved dimnames, whereas in R (< 4.4.0) it doesn't. For example,

in R 4.3.1:

> x <- array(1:6, dim = c(2, 3), dimnames = list(c("A", "B"), c("a", "b", "c")))
> str(dimnames(x))
List of 2
 $ : chr [1:2] "A" "B"
 $ : chr [1:3] "a" "b" "c"
> dim(x) <- dim(x)
> str(dimnames(x))
 NULL

whereas in R-devel:

> x <- array(1:6, dim = c(2, 3), dimnames = list(c("A", "B"), c("a", "b", "c")))
> str(x)
 int [1:2, 1:3] 1 2 3 4 5 6
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:2] "A" "B"
  ..$ : chr [1:3] "a" "b" "c"
> dim(x) <- dim(x)
> str(x)
 int [1:2, 1:3] 1 2 3 4 5 6
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:2] "A" "B"
  ..$ : chr [1:3] "a" "b" "c"

Thus, our assumption in our tests that dim(y) <- dim(x) removed dimnames is no longer correct. We do that in many places, e.g.

https://github.com/HenrikBengtsson/matrixStats/blob/e173995f086eaf73c8c8c204bd6f043203bf1492/tests/rowCumMinMaxs.R#L3-L14

The quick fix would be to add dimnames(y) <- NULL, e.g.

   dim(y) <- dim(x) 
   dimnames(y) <- NULL
   dimnames <- dimnames(x) 
HenrikBengtsson commented 8 months ago

The modification in R-devel causing this has been reverted.