Learn R Programming

RMassBank (version 2.0.0)

formulastring.to.list: Interconvert molecular formula representations

Description

Converts molecular formulas from string to list representation or vice versa.

Usage

list.to.formula(flist)
formulastring.to.list(formula)

Arguments

formula
A molecular formula in string format, e.g. "C6H12O6".
flist
A molecular formula in list format, e.g. list( "C" = 6, "H" = 12, "O" = 6 ).

Value

list.to.formula returns a string representation of the formula; formulastring.to.list returns the list representation.

Details

The function doesn't care about whether your formula makes sense. However, "C3.5O4" will give list("C" = 3, "O" = 4) because regular expressions are used for matching (however, list("C" = 3.5, "O" = 4) gives "C3.5O4".) Duplicate elements cause problems; only "strict" molecular formulas ("CH4O", but not "CH3OH") work correctly.

See Also

add.formula, order.formula, is.valid.formula

Examples

Run this code

#
	list.to.formula(list("C" = 4, "H" = 12))
	# This is also OK and useful to calculate e.g. adducts or losses.
	list.to.formula(list("C" = 4, "H" = -1))
	formulastring.to.list(list.to.formula(formulastring.to.list("CHIBr")))

Run the code above in your browser using DataLab