Combines a chemical formula with a specified adduct, and returns the resultant summed formula. This function can handle addition or subtraction of elements from the main formula based on the adduct.

sum_formula(formula = "C9H11NO2", adduct = "M-H2O+H")

Arguments

formula

A character string representing the base chemical formula. Default is "C9H11NO2".

adduct

A character string representing the adduct to be added or subtracted from the base formula. Examples include "M-H2O+H", "M+", and "M-". Default is "M-H2O+H".

Value

A character string of the resulting chemical formula after combining the base formula with the adduct. If an error occurs or the summation results in negative counts for any element, it returns `NA`.

Author

Xiaotao Shen <shenxt1990@outlook.com>

Examples

sum_formula(formula = "C9H11NO2", adduct = "M+H")
#> [1] "C9H12NO2"
sum_formula(formula = "C9H11NO2", adduct = "M+")
#> [1] "C9H11NO2"
sum_formula(formula = "C9H11NO2", adduct = "M+CH3COOH")
#> [1] "C11H15NO4"
sum_formula(formula = "C9H11", adduct = "M-H20")
#> [1] NA