Skip to content

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

Open

Description

@PAAC1984

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

Activity

  1. GegznaV commented on Nov 16, 2021

    @GegznaV
    Member

    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.
  2. PAAC1984 commented on Nov 16, 2021

    @PAAC1984
    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)
    }

  3. GegznaV commented on Nov 17, 2021

    @GegznaV
    Member

    Thank you @PAAC1984.

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

  4. GegznaV commented on Nov 17, 2021

    @GegznaV
    Member

    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).

  5. GegznaV commented on Nov 17, 2021

    @GegznaV
    Member

    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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions