knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# packages library(elco) library(magrittr) library(dplyr) library(tibble)
This vignette shows how to:
Convert the units of element ratios.
Compute element ratios for different elements.
Compute the nominal oxidation state of carbon (C$_\textrm{ox}$), the oxidative ratio (OR), and the degree of unsaturation.
Load the example data (simulated CHNO content data and sample masses for five samples):
d <- elco::chno
Objects of class elco
may have simple units that represent masses (e.g. g, mg, ...) or molar amounts (e.g. mol, mmol, ...). Moreover, they may have fractional units composed of these simple units, e.g. g/g, mol/g, ... . elco_el_convert
converts between all these units, automatically taking into account if such a conversion requires multiplication with or division by the molar mass of an element or the mass of the sample. A few examples:
# from g/g to g elco::elco_elco_convert(d$C, to = "g", sample_mass = d$sample_mass) # from g/g to mol elco::elco_elco_convert(d$C, to = "mol", sample_mass = d$sample_mass) # from g/g to mol/g elco::elco_elco_convert(d$C, to = "mol/g", sample_mass = NULL) # from mol to g/g elco::elco_elco_convert(d$C, to = "mol", sample_mass = d$sample_mass) %>% elco::elco_elco_convert(to = "g/g", sample_mass = d$sample_mass)
If, for a conversion, the sample mass is requires, as for example from g/g to mol, the sample mass has to be provided as argument sample_mass
. If this is not the case, the function will throw an error:
# from g/g to mol/g: sample_mass not needed elco::elco_elco_convert(d$C, to = "mol/g", sample_mass = NULL) # from g/g to g: sample_mass needed elco::elco_elco_convert(d$C, to = "g", sample_mass = NULL) # from g/g to g: sample_mass needed elco::elco_elco_convert(d$C, to = "g", sample_mass = d$sample_mass)
Element ratio are easily computed:
# compute the C:N ratio (masses) d <- d %>% dplyr::mutate(cn = C/N)
During this, the elco
class attributes are lost since the result is no element content any more. The result keeps the units and errors:
class(d$cn) d$cn
If one wishes to compute other element ratios, e.g. molar ratios, one has to convert the respective units beforehand:
# compute the C:N ratio (molar) d <- d %>% dplyr::mutate(cn_molar = elco::elco_elco_convert(C, to = "mol/g")/elco::elco_elco_convert(N, to = "mol/g")) # plot both C:N ratios for comparison plot(errors::drop_errors(d$cn) ~ errors::drop_errors(d$cn_molar))
elco_elco_convert_df
makes unit conversion and computation of many element ratios much easier. It converts the units of all elco
columns in a data.frame
to a specified unit:
# convert all elcos to mol d_mol <- d %>% elco::elco_elco_convert_df(to = "mol", sample_mass = d$sample_mass) # all elcos in mol now: d_mol # easier computation of many element ratios d <- d %>% elco::elco_elco_convert_df(to = "mol", sample_mass = d$sample_mass) %>% dplyr::mutate(cn_molar = C/N, ch_molar = C/H, co_molar = C/O) # plot C:N ~ C:O plot(errors::drop_errors(d$cn_molar) ~ errors::drop_errors(d$co_molar))
Functions elco_nosc
, elco_or
, and elco_du
enable the computation of the C$_\textrm{ox}$, OR, and degree of unsaturation, respectively [@Worrall.2016b].
# compute nosc, or, and du d <- d %>% elco::elco_elco_convert_df(to = "mol", sample_mass = d$sample_mass) %>% dplyr::mutate( nosc = elco_nosc(C, H, N, O), or = elco_or(C, H, N, O), du = elco_du(C, H, N) ) # show result head(d %>% dplyr::select(nosc, or, du))
As shown, this requires that all element contents are given as molar amounts
# reconvert to mass d <- d %>% elco::elco_elco_convert_df(to = "g/g", sample_mass = d$sample_mass) # this throws errors: with(d, elco_nosc(C, H, N, O)) with(d, elco_or(C, H, N, O)) with(d, elco_du(C, H, N))
This Rmarkdown template is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
Title: Computation with element contents - unit conversion, element ratios, nominal oxidation state of carbon, oxidative ratio, and degree of unsaturation
Author: Henning Teickner
Date: 2020-10-01
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.