Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PAAC1984 opened this issue Nov 16, 2021 · 5 comments
Assignees

Comments

@PAAC1984
Copy link

PAAC1984 commented Nov 16, 2021

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:

  • "myString\r\n\test"
  • "myString\r\n\test\r\n\"

Do seem to work.

Let me know if there are further questions on this.

Best regards,

Patrick

@GegznaV
Copy link
Member

GegznaV commented Nov 16, 2021

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:

  • what R version do you use?
  • what hyperSpec version do you use?
  • what operating system do you use?
  • what operating system was used to create the data file?
  • could you provide an example of a data file? You may zip it and drag-and-drop here.
  • could you provide a minimal reproducible example of code (a.k.a, reprex) that reproduces the reproduction of the issue. I recommend using reprex package to generate a reprex.
  • If possible, show us how the expected result should look like.

@PAAC1984
Copy link
Author

  • what R version do you use?
    

3.6.0 (2019-04-26)

  • what hyperSpec version do you use?
    

hyperSpec_0.100.0

  • what operating system do you use?
    

Windows 10 x64

  • what operating system was used to create the data file?
    

Windows 10 x64

  • could you provide an example of a data file? You may zip it and drag-and-drop here.
    

Example_spectra.zip

  • could you provide a minimal reproducible example of code (a.k.a, reprex) that reproduces the reproduction of the issue. I recommend using reprex package to generate a reprex.
    

library(hyperSpec)
hyperSpec::read.spc("../Example_spectra.spc")

  • If possible, show us how the expected result should look like.
    

In the function "hyperSpec:::string.split" adjust the following line:
x <- apply(pos, 1, function(p, x) substr(x, p[1], p[2]),
x)

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
Copy link
Member

GegznaV commented Nov 17, 2021

Thank you @PAAC1984.

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

@GegznaV
Copy link
Member

GegznaV commented Nov 17, 2021

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
Copy link
Member

GegznaV commented Nov 17, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants