data length differs from size of matrix warning on CRAN check

Viewed 141

Any ideas why the below code snippet (from spatialEco::insert function) would be returning a data length differs from size of matrix warning on a CRAN check? I cannot recreate this warning but, am getting an email from CRAN that a large group of packages is getting this warning on check of examples. One of mine got flagged and I am not sure of the source of the error. This packages (and this specific function) has been around for sometime, why am I getting a check warning now? The other 65 package maintainers are probably asking themself the same question.

Admittedly, I am probably being dense and missing something here but, I have run the package through: rcmdchec::rcmdcheck (with various flag combinations), rcmdchec::compare_to_cran (with all available flavors) as well as submitting to https://win-builder.r-project.org/ and https://builder.r-hub.io and cannot recreate the warning.

x <- data.frame(ID=1:10, y=runif(10))
idx =2
 value = rep(NA, nrow(x))
   x[seq(idx+1, nrow(x)+1),] <- x[seq(idx, nrow(x)),]
     x[idx,] <- value

Here is the resulting warning that CRAN indicates is being returned. It seems to have something to do with piping in new values but, not sure why this is suddenly returning a warning and why it is a matrix size issue.

annet% grep -r "data length differs from size of matrix" spatialEco.Rcheck/ spatialEco.Rcheck/spatialEco-Ex.Rout: data length differs from size of matrix: [10 != 1 x 2]

Warning in matrix(value, n, p) : data length differs from size of matrix: [10 != 1 x 2]

traceback() 9: matrix(value, n, p) 8: [<-.data.frame(*tmp*, idx, , value = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)) 7: [<-(*tmp*, idx, , value = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)) 6: insert(d, idx = 2) at Rex1c630657f5bf04#10

1 Answers

The obvious prevails. The "value" was incorrectly specified. In this example "value" produces a length of 10 rather than 2. It should be value = rep(NA, ncol(x)). This snippet is from the function spatialEco::insert with the MARGIN argument 1. With MARGIN=2 the results were correct because nrow was called with this condition, this was just a stupid syntax error that R ignored, just taking the number of elements needed and ignoring the rest. Here is the source for the function in question.

I am surprised that the CRAN checks ignored this behavior/bug for so long. So, I guess this was a good thing but, it is interesting that we are getting a notice on a development version of R with warning that our package will be removed from CRAN in a few weeks if not addressed.

Related