formulastring.to.list: Interconvert molecular formula representations

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/formulaCalculator.R

Description

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

Usage

1
2
3

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 ).

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.

Value

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

Author(s)

Michael Stravs

See Also

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

Examples

1
2
3
4
5
#
	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")))

sneumann/RMassBank documentation built on Oct. 20, 2020, 3:19 p.m.