read.spc cannot handle spectra files with only one line in the audit log that ends with "\r\n"
PAAC1984 opened this issue · 5 comments
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
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.
-
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.
-
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)
}
Thank you @PAAC1984.
@cbeleites, could you look into this? Does this issue belong to hyperSpec
or to hySpc.read.spc
?
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).
GitHub does not allow transferring the issue to the particular hySpc.read.spc
repo. But the following discussion must continue there: