Skip to content

The absence of a check for element symbols #49

@AndreySamokhin

Description

@AndreySamokhin

I have used the IsoSpecR package (ver. 2.1.3) to calculate the isotopic distribution for more than a million formulas. After several dozens of thousands of compounds R crashed with the following message "R Session Aborted" (any error was not thrown). Each time it was a different number of formulas (from 10'000 to 200'000). I tried several approaches, none of which was successful. Finally, I found out that my dataset contained some formulas with elements that do not have stable isotopes (e.g., C18H25AcNO5S or C20H29BClN6O6Tc). Excluding all such formulas from consideration allowed me to finish the calculation.

One can conclude that any check for passed element symbols is absent and any character combination can be fed to the IsoSpecR::IsoSpecify() function. Such behavior can result in unexpected results. See some examples below.

# Example 1.
# R crashes with the "R Session Aborted" message.
formulas <- list(
  c(Tc = 1),
  c(H = 7, Tc = 1),
  c(O = 1, Tc = 1),
  c(H = 2, O = 1, Tc = 1),
  c(C = 1, O = 1, Tc = 1),
  c(C = 1, H = 2, O = 1, Tc = 1),
  c(O = 2, Tc = 1),
  c(S = 1, Tc = 1),
  c(H = 2, S = 1, Tc = 1),
  c(H = 4, O = 2, Tc = 1)
)
for (i in 1:1000) {
  temp <- lapply(formulas, function(x) { IsoSpecR::IsoSpecify(x, 0.95) })
}


# Example 2.
# Adding an 'unsupported' element does not change the output. Any message or
# error is not returned.
formula1 <- c(C = 18, H = 25, Ac = 1, N = 1, O = 5, S = 1)
formula2 <- c(C = 18, H = 25, N = 1, O = 5, S = 1)
identical(IsoSpecR::IsoSpecify(formula1, 0.95),
          IsoSpecR::IsoSpecify(formula2, 0.95))
#> [1] TRUE

I would have expected to get an error or warning message when the passed symbol was not supported. This issue cost me several hours therefore I decided to share my experience. Hope somebody finds it useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions