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

Error in diff2(x, differences = diff) : names() applied to a non-vector #258

Open HenrikBengtsson opened 2 months ago

HenrikBengtsson commented 2 months ago

See https://github.com/ccagc/QDNAseq/issues/123, which reports on:

  Error in diff2(x, differences = diff) : names() applied to a non-vector
  Calls: plot -> plot -> .local -> apply -> FUN -> sdDiff -> diff2

That error message is produced in checkNames(SEXP x, SEXP s) at:

https://github.com/wch/r-source/blob/b046c0c5273ffb44037a0fde606d203ab773bca1/src/main/attrib.c#L416

The only place where I see checkNames() being called is from namesgets(SEXP vec, SEXP val) at:

https://github.com/wch/r-source/blob/b046c0c5273ffb44037a0fde606d203ab773bca1/src/main/attrib.c#L994

We call diff2() -> setNamesDiff() -> namesgets() in:

https://github.com/HenrikBengtsson/matrixStats/blob/76a9c6ccd152bcb335d36cf1273b3edf9ceaae95/src/naming.c#L56

However, I fail to see how we can reach the statement that generates the error message. It could be that there is a memory leak that causes it to happen, as reported in https://github.com/ccagc/QDNAseq/issues/123#issuecomment-1944219672;

  *** caught segfault ***
  address (nil), cause 'unknown'

  Traceback:
   1: diff2(x, differences = diff)
   2: sdDiff(x, ..., trim = trim)