A function to validate chemical formulas based on the list of recognized chemical elements as of 2022.

is_valid_chemical_formula(formula)

Arguments

formula

Character string representing the chemical formula to be checked.

Value

Logical. Returns `TRUE` if the formula is valid and `FALSE` otherwise.

Details

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.

Author

Xiaotao Shen shenxt1990@outlook.com

Examples

is_valid_chemical_formula("H2O")      # TRUE
#> [1] TRUE
is_valid_chemical_formula("C6H12O6")  # TRUE
#> [1] TRUE
is_valid_chemical_formula("H2ZO4")    # FALSE
#> [1] FALSE