Format a molecular formula as a list of all elements and their counts in Hill order.

# S3 method for mol_form
format(x, prettify = FALSE, ...)

Arguments

x

Molecular formula to be formatted

prettify

If prettify = TRUE, include control characters for pretty printing (blue, positive element counts; red: negative element counts; gray: empty formulas).

...

Further arguments passed to or from other methods.

Value

A character representation of the molecular formula.

Examples

molecular_formula("N-1 H-3") %>% format()
#> [1] "H-3 N-1"
molecular_formula("N-1 H-3") %>% format(prettify = TRUE)
#> [1] "H\033[31m-3\033[39m N\033[31m-1\033[39m"
molecular_formula("P+1 O+3 H+1") %>% format()
#> [1] "H O3 P"
molecular_formula("P+1 O+3 H+1") %>% format(prettify = TRUE)
#> [1] "H O\033[34m3\033[39m P"