r-hyperspec / hyperSpec

hyperSpec: Tools for Spectroscopy (R package)
https://r-hyperspec.github.io/hyperSpec/
GNU General Public License v3.0
12 stars 3 forks source link

read.spc cannot handle spectra files with only one line in the audit log that ends with "\r\n" #64

Open PAAC1984 opened 2 years ago

PAAC1984 commented 2 years ago

Hi,

I'm using hyperSpec to process Grams spectral data(*.spc files) and recently I received the following error:

Error in apply(pos, 1, function(p, x) substr(x, p[1], p[2]), x) : 
  dim(X) must have a positive length

After tracing down the function in the code, it looks like the origin is in the "hyperSpec:::split.string" function. What happens is when variable "x" only has one line and ends with "\r\n\" (for example "myString\r\n\"), the pos matrix will turn into an array rather then a matrix and cause the error above.

Alternate versions of strings using "r\n\" like:

Do seem to work.

Let me know if there are further questions on this.

Best regards,

Patrick

GegznaV commented 2 years ago

Hello, Patric (@PAAC1984),

Thanks for contacting us. It seems that the issue is OS-specific, as you indicate that it is related to \r\n. I have a few additional questions:

PAAC1984 commented 2 years ago

To include a check whether the variable "pos" is a matrix(which has dimensions), otherwise it should be an array according on how the script acts: if(!is.null(dim(pos))){ x <- apply(pos, 1, function(p, x) substr(x, p[1], p[2]), x) } else { x <- substr(x, pos[1], pos[2]) return(x) }

GegznaV commented 2 years ago

Thank you @PAAC1984.

@cbeleites, could you look into this? Does this issue belong to hyperSpec or to hySpc.read.spc?

GegznaV commented 2 years ago

I can reproduce the issue with hySpc.read.spc package:

hySpc.read.spc::read.spc("Example_spectra.spc")
## Error in apply(pos, 1, function(p, x) substr(x, p[1], p[2]), x) : 
## dim(X) must have a positive length

It seems that function read.spc() is not renamed into read_spc() yet. And internal function split.string() is now a part of hySpc.read.spc package (so I'll migrate the issue to the appropriate repo).

GegznaV commented 2 years ago

GitHub does not allow transferring the issue to the particular hySpc.read.spc repo. But the following discussion must continue there: