formulastring.to.list {RMassBank} | R Documentation

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

### 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

    #
    	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")))

[Package RMassBank version 2.8.0 Index]