Closed henningte closed 2 years ago
@cbeleites could you take care of this?
This type of error has brought down other packages as well, like kableExtra
which is very broadly used.
@eoduniyi might be the most knowledgeable to fix it in both packages but of course @cbeleites will have to submit the revision to CRAN.
Thanks @henningte for a careful and detailed explanation of the problem, this will expedite the repair.
I am working on this, will push a branch hopefully in the next hour.
https://github.com/r-hyperspec/hyperSpec/pull/81 @cbeleites has been requested to review, one oddball problem with vdiffr
on Ubuntu during checks. Otherwise OK.
I will fix hySpc.read.spc
in a similar fashion once this is approved.
Hi @bryanhanson, many thanks for taking care of this so fast. I had a glance at your solution but will need to think whether it actually does what we want to do.
I have a sneaking suspicion that we rather want to make sure x
is of length 1, thus length(pos)
will always be 1, and it will always be a list.
The intended check would then be if (length(pos[[1]]) == 1 && pos[[1]][1] == -1)
.
After all, we throw away all results on x[-1]
in the next line.
I'd like to check what happens with @henningte 's test file, though.
@henningte
I don't know if you have received a message from CRAN reporting this error --- perhaps not if there are no tests for
read.spc()
One of the reasons why we want to split hyperSpec into smaller packages is that the size limits on CRAN do not allow us to ship the test files which we have offline. For the smaller packages, we hope to either include them, or we'll provide the package outside CRAN on github.
x <- "Vilmantas"
pos <- gregexpr("z", x)
if (length(pos) == 1 & pos[[1]][[1]] == -1) {
cat("string was not split\n")
# return(x)
}
But yes @cbeleites one could check it other ways, but the key thing is don't use &&, use &. CRAN wants a length one item compared to a length one item.
@bryanhanson I understood that CRAN wants a length 1 logical inside the if
.
My reasoning is that we want to have a warning/error in situations like now because it actually reveals a bug in the code.
pos[[1]][1]
should be of length 1. Actually, if checking length(x) == 1
and length(pos[[1]]) == 1
, we should be able to check whether pos[[1]] == -1
, as before.
Whenever we encounter a warning/errror on that, we found a situation that is fundamentally outside what I was thinking about when writing this function.
I'm open to the argument that being forced to do hurried fixes due to CRAN finding something that was never checked before is worse, though. :-)
Thank you for handling the issue that quickly.
Here is a direct link to the sample spc
file: https://github.com/henningte/ir/blob/main/inst/extdata/1.spc
Thanks for the file Henning. The version in PR #81 reads this file w/o problems.
To remove pressures on both 'ir' and a potential 'hyperSpec' CRAN update, I have now patched 'ir' on CRAN such that the error disappears. Thanks to the fixes from @bryanhanson, metadata can still be imported with the GitHub version.
So, from my side, there is no urgency any more to update 'hyperSpec' on CRAN, and this is the best solution for all of us, I hope!
Seems to be solved in this repo:
library(ir)
x <-
hyperSpec::read.spc(
filename = system.file("extdata/1.spc", package = "ir"),
log.txt = TRUE,
log.bin = TRUE,
log.disk = TRUE,
keys.hdr2data = TRUE,
keys.log2data = TRUE,
no.object = FALSE
)
#> Warning: Function 'hyperSpec::read.spc' is deprecated.
#> Please, find alternatives in package 'hySpc.read.spc'
#> https://r-hyperspec.github.io/hySpc.read.spc
x
#> hyperSpec object
#> 1 spectra
#> 45 data columns
#> 1765 data points / spectrum
Created on 2022-07-15 by the reprex package (v2.0.1)
And in hySpc.read.spc
https://github.com/r-hyperspec/hySpc.read.spc/pull/22:
library(ir)
y <-
hySpc.read.spc::read_spc(
filename = system.file("extdata/1.spc", package = "ir"),
log_txt = TRUE,
log_bin = TRUE,
log_disk = TRUE,
keys_hdr2data = TRUE,
keys_log2data = TRUE,
no_object = FALSE
)
y
#> hyperSpec object
#> 1 spectra
#> 45 data columns
#> 1765 data points / spectrum
Created on 2022-07-15 by the reprex package (v2.0.1)
read.spc()
throws the warning in the reprex below with R 4.2.0. This warning will become an error in R-devel within a week (see https://www.stats.ox.ac.uk/pub/bdr/LENGTH1/00README.txt).I have just today published an R package 'ir' on CRAN which depends on 'hyperSpec' for importing
spc
files. Also today, I got the message that 'ir' will be removed if this issue does not get fixed until 2022-05-09. I don't know if you have received a message from CRAN reporting this error --- perhaps not if there are no tests forread.spc()
.Here's the reprex throwing the warning
Created on 2022-04-25 by the reprex package (v2.0.1)
Session info
``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.0 (2022-04-22 ucrt) #> os Windows 10 x64 (build 19044) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate German_Germany.utf8 #> ctype German_Germany.utf8 #> tz Europe/Berlin #> date 2022-04-25 #> pandoc 2.17.1.1 @ C:/Program Files/RStudio/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> brio 1.1.3 2021-11-30 [1] CRAN (R 4.2.0) #> cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0) #> crayon 1.5.1 2022-03-26 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> dplyr 1.0.8 2022-02-08 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.2.0) #> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.2.0) #> hyperSpec * 0.100.0 2021-09-13 [1] CRAN (R 4.2.0) #> jpeg 0.1-9 2021-07-24 [1] CRAN (R 4.2.0) #> knitr 1.38 2022-03-25 [1] CRAN (R 4.2.0) #> lattice * 0.20-45 2021-09-22 [2] CRAN (R 4.2.0) #> latticeExtra 0.6-29 2019-12-19 [1] CRAN (R 4.2.0) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> png 0.1-7 2013-12-03 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.2.0) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0) #> rmarkdown 2.13 2022-03-10 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0) #> scales 1.2.0 2022-04-13 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0) #> testthat 3.1.3 2022-03-29 [1] CRAN (R 4.2.0) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.2.0) #> xml2 * 1.3.3 2021-11-30 [1] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/henni/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-4.2.0/library #> #> ────────────────────────────────────────────────────────────────────────────── ```The sample
spc
file can be found as external data in the 'ir' package.I have traced back the error to this line in
.spc.log()
:https://github.com/r-hyperspec/hyperSpec/blob/66f31c568ec909c107b3541f5601c7f4fba391d1/R/DEPRECATED-read.spc.R#L557
(I've seen that the current CRAN version code is a bit different here)
And ultimately, the warning (error) is caused by this line in
split.string()
:https://github.com/r-hyperspec/hyperSpec/blob/66f31c568ec909c107b3541f5601c7f4fba391d1/R/DEPRECATED-read.spc.R#L902
The problem is that with the sample
spc
file,pos
is a list:And the first element (as used in
split.string()
) ---pos[[1]]
--- is:i.e. a vector. For this reason, the line in
split.string()
returns a logical vector with more than one element which causes the warning.Unfortunately, I have no deeper knowledge on the decoding of the
spc
files inhyperSpec
, so I don't know what would be the best option to fix this warning (error). Naively, I would suggest (assumingpos[[1]]
is supposed to refer to the first position inpos
) to writepos[[1]][[1]]
instead ofpos[[1]]
.If you have any idea here, this would be great. I have seen that the hyperSpec package is under heavy development right now and that the
read.spc()
function gets its own sub-package. I don't know what solution would fit into your plan.Please let me know if you cannot resolve this soon such that I can adopt 'ir' to avoid it from being removed from CRAN (e.g. by temporarily removing the example).
Edit: I've tested if the warning (error) also occurs with the current GitHub version of both 'hyperSpec' and 'hySpc.read.spc' (and I can confirm this):
Created on 2022-04-25 by the reprex package (v2.0.1)
Session info
``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.0 (2022-04-22 ucrt) #> os Windows 10 x64 (build 19044) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate German_Germany.utf8 #> ctype German_Germany.utf8 #> tz Europe/Berlin #> date 2022-04-25 #> pandoc 2.17.1.1 @ C:/Program Files/RStudio/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> brio 1.1.3 2021-11-30 [1] CRAN (R 4.2.0) #> cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0) #> crayon 1.5.1 2022-03-26 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> dplyr 1.0.8 2022-02-08 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.2.0) #> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.2.0) #> hyperSpec * 0.200.0.9000 2022-04-25 [1] Github (r-hyperspec/hyperSpec@66f31c5) #> hySpc.read.spc * 0.0.0.9000 2022-04-25 [1] Github (r-hyperspec/hySpc.read.spc@8eb1f1a) #> hySpc.testthat 0.2.1.9000 2022-04-25 [1] Github (r-hyperspec/hySpc.testthat@3d046e3) #> jpeg 0.1-9 2021-07-24 [1] CRAN (R 4.2.0) #> knitr 1.38 2022-03-25 [1] CRAN (R 4.2.0) #> lattice * 0.20-45 2021-09-22 [2] CRAN (R 4.2.0) #> latticeExtra 0.6-29 2019-12-19 [1] CRAN (R 4.2.0) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> png 0.1-7 2013-12-03 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.2.0) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.2.0) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.2.0) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.2.0) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0) #> rmarkdown 2.13 2022-03-10 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0) #> scales 1.2.0 2022-04-13 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0) #> styler 1.7.0 2022-03-13 [1] CRAN (R 4.2.0) #> testthat 3.1.3 2022-03-29 [1] CRAN (R 4.2.0) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.2.0) #> xml2 1.3.3 2021-11-30 [1] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/henni/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-4.2.0/library #> #> ────────────────────────────────────────────────────────────────────────────── ```