This function checks whether a given chemical formula is valid based on standard conventions. It ensures that element symbols are followed by valid numeric subscripts (if present). The function uses a list of known chemical elements up to 2022. It returns TRUE if the formula is valid, otherwise returns FALSE.

check_chemical_formula(formula)

Arguments

formula

A character string representing the chemical formula to be validated.

Value

A logical value: TRUE if the formula is valid, FALSE otherwise.

Examples

check_chemical_formula("H2O") # TRUE
#> [1] TRUE
check_chemical_formula("2H") # FALSE
#> [1] TRUE