R/2-chemical_formula_funcitons.R
is_valid_chemical_formula.Rd
A function to validate chemical formulas based on the list of recognized chemical elements as of 2022.
is_valid_chemical_formula(formula)
Character string representing the chemical formula to be checked.
Logical. Returns `TRUE` if the formula is valid and `FALSE` otherwise.
Check Validity of a Chemical Formula
Determines the validity of a chemical formula based on the known chemical elements up to 2022. The function checks whether all the symbols in the formula belong to the list of known chemical elements. It doesn't consider charges or other non-element symbols in the formula.
is_valid_chemical_formula("H2O") # TRUE
#> [1] TRUE
is_valid_chemical_formula("C6H12O6") # TRUE
#> [1] TRUE
is_valid_chemical_formula("H2ZO4") # FALSE
#> [1] FALSE