Learn R Programming

ume (version 1.5.2)

convert_data_table_to_molecular_formulas: Convert Data Table with Element Counts to Molecular Formulas

Description

Creates a character vector of molecular formulas and adds it as a column to the input data.table. The molecular formula string follows the Hill system order for element arrangement. If keep_element_sums == TRUE, a data.table is returned that also provides the sum of atoms of each element in the molecular formula.

Usage

convert_data_table_to_molecular_formulas(
  mfd,
  isotope_formulas = FALSE,
  keep_element_sums = FALSE,
  verbose = FALSE,
  ...
)

Value

The original table mfd as data.table having additional columns:

mf

Standardized molecular formula following the Hill order.

mf_iso

If isotope_formulas = TRUE: Standardized molecular formula considering all isotopes of an element.

C_tot

If keep_element_sums = TRUE: The total count of all atoms that are carbon isotopes (similar for all other elements.

Arguments

mfd

data.table with molecular formula data as derived from ume::assign_formulas. Column names of elements/isotopes must match names in the isotope column of ume::masses; values are integers representing counts per formula.

isotope_formulas

Logical. If TRUE the output table will have an additional molecular formula string that includes isotope information (e.g. "[12C5][13C1][1H12][16O6]")

keep_element_sums

description. If TRUE the output table will have additional columns containing the total count of atoms of an element (e.g. S_tot).

verbose

logical; if TRUE, show progress messages.

...

Additional arguments passed to methods.

Notes

  • The function correctly handles isotopic notations such as [13C] and [18O2].

  • The output follows the Hill order, meaning C, H first, followed by other elements in alphabetical order.

  • Single-element counts (e.g., C1H4CH4) are formatted without explicit 1.

Details

This function extracts element or isotope counts from a table with columns for each element of a molecular formula, including those with isotopic notation. It ensures that only valid elements are included based on a reference table (masses).

The function internally uses the ume::masses table that contains element and isotopic symbols.

See Also

Other molecular formula functions: convert_molecular_formula_to_data_table()

Examples

Run this code
convert_data_table_to_molecular_formulas(mf_data_demo[, .(`12C`, `1H`, `14N`, `16O`, `31P`, `32S`)])

Run the code above in your browser using DataLab