Skip to content

get.formula fails if elements has length one #129

@meowcat

Description

@meowcat

generate.formula gets an error if the specified element list has only one element specified. Inserting a dummy element with max count of zero circumvents the issue. Of course, I don't know if the actual root cause has anything to to with list length.

generate.formula(120, window = 0.0036, list(c("C", "0", "12")))
# Error in .jcall(mfTool, "Lorg/openscience/cdk/interfaces/IMolecularFormulaSet;",  : 
#  java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

generate.formula(120, window = 0.0036, list(c("C", "0", "12"), c("H", "0", "0")))
# [[1]] cdkFormula:  C10 , mass =  120 , charge =  0

generate.formula(120, window = 0.0036, list(c("H", "0", "200")))
# Error in .jcall(mfTool, "Lorg/openscience/cdk/interfaces/IMolecularFormulaSet;",  : 
#  java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

list(c("C", "0", "12")) is in fact a list of length one, so the issue isn't that it got converted to a list of length 3:

list(c("C", "0", "12"))
# [[1]]
# [1] "C"  "0"  "12"

(I am aware that the doc specifies c("C", 0, 50) but of course 0 and 50 get converted to character anyway.)

System (please complete the following information):

> session_info()
- Session info -------------------------------------------------------------------------------------------------------------------------------------------
 setting  value
 version  R version 4.1.2 (2021-11-01)
 os       Windows 10 x64 (build 19042)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.1252
 ctype    English_United States.1252
 tz       Europe/Berlin
 date     2022-03-17
 rstudio  2021.09.0+351 Ghost Orchid (desktop)
 pandoc   2.14.0.3 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)

- Packages -----------------------------------------------------------------------------------------------------------------------------------------------
 ! package        * version  date (UTC) lib source
   affy             1.72.0   2021-10-26 [1] Bioconductor
   affyio           1.64.0   2021-10-26 [1] Bioconductor
   assertthat       0.2.1    2019-03-21 [1] CRAN (R 4.1.1)
   backports        1.4.1    2021-12-13 [1] CRAN (R 4.1.2)
   base64enc        0.1-3    2015-07-28 [1] CRAN (R 4.1.1)
   Biobase          2.54.0   2021-10-26 [1] Bioconductor
   BiocGenerics   * 0.40.0   2021-10-26 [1] Bioconductor
   BiocManager      1.30.16  2021-06-15 [1] CRAN (R 4.1.1)
   BiocParallel     1.28.3   2021-12-09 [1] Bioconductor
   bitops           1.0-7    2021-04-24 [1] CRAN (R 4.1.1)
   brio             1.1.3    2021-11-30 [1] CRAN (R 4.1.2)
   broom            0.7.12   2022-01-28 [1] CRAN (R 4.1.2)
   cachem           1.0.6    2021-08-19 [1] CRAN (R 4.1.1)
   callr            3.7.0    2021-04-20 [1] CRAN (R 4.1.1)
   caTools          1.18.2   2021-03-28 [1] CRAN (R 4.1.2)
   cellranger       1.1.0    2016-07-27 [1] CRAN (R 4.1.1)
   ChemmineOB       1.32.0   2021-10-26 [1] Bioconductor
   ChemmineR        3.46.0   2021-10-26 [1] Bioconductor
   cli              3.2.0    2022-02-14 [1] CRAN (R 4.1.2)
   clue             0.3-60   2021-10-11 [1] CRAN (R 4.1.1)
   cluster          2.1.2    2021-04-17 [2] CRAN (R 4.1.2)
   codetools        0.2-18   2020-11-04 [2] CRAN (R 4.1.2)
   colorspace       2.0-3    2022-02-21 [1] CRAN (R 4.1.2)
   crayon           1.5.0    2022-02-14 [1] CRAN (R 4.1.2)
   data.table       1.14.2   2021-09-27 [1] CRAN (R 4.1.1)
   data.tree        1.0.0    2020-08-03 [1] CRAN (R 4.1.2)
   DBI              1.1.2    2021-12-20 [1] CRAN (R 4.1.2)
   dbplyr           2.1.1    2021-04-06 [1] CRAN (R 4.1.1)
   desc             1.4.1    2022-03-06 [1] CRAN (R 4.1.2)
   devtools       * 2.4.3    2021-11-30 [1] CRAN (R 4.1.2)
   digest           0.6.29   2021-12-01 [1] CRAN (R 4.1.2)
   doParallel       1.0.17   2022-02-07 [1] CRAN (R 4.1.2)
   dplyr          * 1.0.8    2022-02-08 [1] CRAN (R 4.1.2)
   DT               0.21     2022-02-26 [1] CRAN (R 4.1.2)
   ellipsis         0.3.2    2021-04-29 [1] CRAN (R 4.1.1)
   enviPat          2.4      2019-04-07 [1] CRAN (R 4.1.1)
   evaluate         0.15     2022-02-18 [1] CRAN (R 4.1.2)
   fansi            1.0.2    2022-01-14 [1] CRAN (R 4.1.2)
   fastmap          1.1.0    2021-01-25 [1] CRAN (R 4.1.1)
   fingerprint      3.5.7    2018-01-07 [1] CRAN (R 4.1.1)
   forcats        * 0.5.1    2021-01-27 [1] CRAN (R 4.1.1)
   foreach          1.5.2    2022-02-02 [1] CRAN (R 4.1.2)
   Formula          1.2-4    2020-10-16 [1] CRAN (R 4.1.1)
   fs               1.5.2    2021-12-08 [1] CRAN (R 4.1.2)
   generics         0.1.2    2022-01-31 [1] CRAN (R 4.1.2)
   ggplot2        * 3.3.5    2021-06-25 [1] CRAN (R 4.1.1)
   glue             1.6.2    2022-02-24 [1] CRAN (R 4.1.2)
   gplots         * 3.1.1    2020-11-28 [1] CRAN (R 4.1.2)
   gridExtra        2.3      2017-09-09 [1] CRAN (R 4.1.1)
   gtable           0.3.0    2019-03-25 [1] CRAN (R 4.1.1)
   gtools           3.9.2    2021-06-06 [1] CRAN (R 4.1.2)
   haven            2.4.3    2021-08-04 [1] CRAN (R 4.1.1)
   hms              1.1.1    2021-09-26 [1] CRAN (R 4.1.1)
   htmltools        0.5.2    2021-08-25 [1] CRAN (R 4.1.1)
   htmlwidgets      1.5.4    2021-09-08 [1] CRAN (R 4.1.1)
   httr             1.4.2    2020-07-20 [1] CRAN (R 4.1.1)
   impute           1.68.0   2021-10-26 [1] Bioconductor
   IRanges          2.28.0   2021-10-26 [1] Bioconductor
   iterators        1.0.14   2022-02-05 [1] CRAN (R 4.1.2)
   itertools        0.1-3    2014-03-12 [1] CRAN (R 4.1.1)
   jsonlite         1.8.0    2022-02-22 [1] CRAN (R 4.1.2)
   KernSmooth       2.23-20  2021-05-03 [2] CRAN (R 4.1.2)
   knitr            1.37     2021-12-16 [1] CRAN (R 4.1.2)
   lattice          0.20-45  2021-09-22 [2] CRAN (R 4.1.2)
   lifecycle        1.0.1    2021-09-24 [1] CRAN (R 4.1.1)
   limma            3.50.1   2022-02-17 [1] Bioconductor
   logger           0.2.2    2021-10-19 [1] CRAN (R 4.1.1)
   lubridate        1.8.0    2021-10-07 [1] CRAN (R 4.1.1)
   magrittr         2.0.2    2022-01-26 [1] CRAN (R 4.1.2)
   MALDIquant       1.21     2021-12-23 [1] CRAN (R 4.1.2)
   MASS             7.3-54   2021-05-03 [2] CRAN (R 4.1.2)
   memoise          2.0.1    2021-11-26 [1] CRAN (R 4.1.2)
   modelr           0.1.8    2020-05-19 [1] CRAN (R 4.1.1)
   MsCoreUtils      1.6.2    2022-02-24 [1] Bioconductor
   MSnbase          2.20.1   2021-11-14 [1] Bioconductor
   munsell          0.5.0    2018-06-12 [1] CRAN (R 4.1.1)
   mzID             1.32.0   2021-10-26 [1] Bioconductor
   mzR              2.28.0   2021-10-26 [1] Bioconductor
   ncdf4            1.19     2021-12-15 [1] CRAN (R 4.1.2)
   pcaMethods       1.86.0   2021-10-26 [1] Bioconductor
   pillar           1.7.0    2022-02-01 [1] CRAN (R 4.1.2)
   pkgbuild         1.3.1    2021-12-20 [1] CRAN (R 4.1.2)
   pkgconfig        2.0.3    2019-09-22 [1] CRAN (R 4.1.1)
   pkgload          1.2.4    2021-11-30 [1] CRAN (R 4.1.2)
   plyr             1.8.6    2020-03-03 [1] CRAN (R 4.1.1)
   png              0.1-7    2013-12-03 [1] CRAN (R 4.1.1)
   preprocessCore   1.56.0   2021-10-26 [1] Bioconductor
   prettyunits      1.1.1    2020-01-24 [1] CRAN (R 4.1.1)
   processx         3.5.2    2021-04-30 [1] CRAN (R 4.1.1)
   ProtGenerics     1.26.0   2021-10-26 [1] Bioconductor
   ps               1.6.0    2021-02-28 [1] CRAN (R 4.1.1)
   purrr          * 0.3.4    2020-04-17 [1] CRAN (R 4.1.1)
   R.methodsS3      1.8.1    2020-08-26 [1] CRAN (R 4.1.1)
   R.oo             1.24.0   2020-08-26 [1] CRAN (R 4.1.1)
   R.utils          2.11.0   2021-09-26 [1] CRAN (R 4.1.2)
   R6               2.5.1    2021-08-19 [1] CRAN (R 4.1.1)
   rcdk           * 3.6.0    2021-10-17 [1] CRAN (R 4.1.1)
   rcdklibs       * 2.3      2020-03-08 [1] CRAN (R 4.1.1)
   Rcpp           * 1.0.8    2022-01-13 [1] CRAN (R 4.1.2)
   RCurl            1.98-1.6 2022-02-08 [1] CRAN (R 4.1.2)
   readJDX          0.6.1    2021-09-20 [1] CRAN (R 4.1.2)
   readr          * 2.1.2    2022-01-30 [1] CRAN (R 4.1.2)
   readxl           1.3.1    2019-03-13 [1] CRAN (R 4.1.1)
   remotes          2.4.2    2021-11-30 [1] CRAN (R 4.1.2)
   reprex           2.0.1    2021-08-05 [1] CRAN (R 4.1.1)
 D rJava          * 1.0-6    2021-12-10 [1] CRAN (R 4.1.2)
   rjson            0.2.21   2022-01-09 [1] CRAN (R 4.1.2)
   rlang            1.0.2    2022-03-04 [1] CRAN (R 4.1.2)
   rmarkdown        2.12     2022-03-02 [1] CRAN (R 4.1.2)
 P RMassBank      * 3.5.2.1  2022-03-17 [?] Bioconductor
   rprojroot        2.0.2    2020-11-15 [1] CRAN (R 4.1.1)
   rstudioapi       0.13     2020-11-12 [1] CRAN (R 4.1.1)
   rsvg             2.2.0    2022-02-07 [1] CRAN (R 4.1.2)
   rvest            1.0.2    2021-10-16 [1] CRAN (R 4.1.1)
   S4Vectors      * 0.32.3   2021-11-21 [1] Bioconductor
   scales           1.1.1    2020-05-11 [1] CRAN (R 4.1.1)
   sessioninfo      1.2.2    2021-12-06 [1] CRAN (R 4.1.2)
   stringi          1.7.6    2021-11-29 [1] CRAN (R 4.1.2)
   stringr        * 1.4.0    2019-02-10 [1] CRAN (R 4.1.1)
   testthat         3.1.2    2022-01-20 [1] CRAN (R 4.1.2)
   tibble         * 3.1.6    2021-11-07 [1] CRAN (R 4.1.2)
   tidyr          * 1.2.0    2022-02-01 [1] CRAN (R 4.1.2)
   tidyselect       1.1.2    2022-02-21 [1] CRAN (R 4.1.2)
   tidyverse      * 1.3.1    2021-04-15 [1] CRAN (R 4.1.1)
   tzdb             0.2.0    2021-10-27 [1] CRAN (R 4.1.1)
   usethis        * 2.1.5    2021-12-09 [1] CRAN (R 4.1.2)
   utf8             1.2.2    2021-07-24 [1] CRAN (R 4.1.1)
   vctrs            0.3.8    2021-04-29 [1] CRAN (R 4.1.1)
   vsn              3.62.0   2021-10-26 [1] Bioconductor
   webchem          1.1.2    2021-12-06 [1] CRAN (R 4.1.2)
   withr            2.5.0    2022-03-03 [1] CRAN (R 4.1.2)
   xfun             0.30     2022-03-02 [1] CRAN (R 4.1.2)
   XML              3.99-0.9 2022-02-24 [1] CRAN (R 4.1.2)
   xml2             1.3.3    2021-11-30 [1] CRAN (R 4.1.2)
   yaml             2.3.5    2022-02-21 [1] CRAN (R 4.1.2)
   zlibbioc         1.40.0   2021-10-26 [1] Bioconductor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions