View source: R/conversion-conc.R
convert_get_R | R Documentation |
Converting between volume and mass concentrations isn't as straightforward as you may think. The molar gas constant is a natur constant. As such is subject to changes if more accurate measurements are avaible. CODATA is a comittee appointed to frequently publish a collection of natur constants. For the molar gas constant for example:
CODATA 1986 8.314510 CODATA 1998 8.314472 CODATA 2010 8.3144621 CODATA 2014 8.3144598
Other questions are the exact values for temperature, pressure and mol masses. This function set allows the customization of all used constants for the conversion. In the example is showed how to use the CODATA 2014 value for the molar gas constant, 1013.25 hPA for the pressure and add Ammoniak (NH3) to the conversions.
convert_get_R()
convert_set_R(R)
convert_get_mol_masses()
convert_set_mol_masses(mol_masses)
convert_get_conc_lookup()
convert_set_conc_lookup(lookup)
R |
new value for molar gas constant in [kg * m2 / (s2 * mol * K)] |
mol_masses |
A tibble with one row, parameter as name of column and mol mass as bare double value in [g / mol] |
lookup |
new lookup table. For Details see section Lookup Table or examples |
The constants for R, mol masses or the lookup table for conversions
The lookup table is used to pick to correct conversion function. The table is a tibble with the columns parameter,
from, to and FUN. The conversion_conc_fun_factory()
uses this lookup table to create a partial function from FUN.
The partial function gets the mol mass (as mol_mass) of the parameter and all ... arguments applied as named
arguments. This allows to change the default values of mass_to_parts()
and parts_to_mass()
.
convert_conc()
conversion_conc_fun_factory()
rlang::is_bare_double()
purrr::partial()
# Update molar mas constant R to CODATA 2014 value
convert_set_R(8.3144598)
# add NH3 to the existing mol masses
mol_masses <- convert_get_mol_masses()
mol_masses <- dplyr::bind_cols(mol_masses, "NH3" = 17.03)
convert_set_mol_masses(mol_masses)
# to update the default pressure rebuild the lookup table
# with partial functions of mass_to_parts, parts_to_mass
# at the same time add mappings for NH3
mass_to_parts_partial <- purrr::partial(mass_to_parts, pressure = 1013.25)
parts_to_mass_partial <- purrr::partial(parts_to_mass, pressure = 1013.25)
lookup <- tibble::tribble(
~parameter, ~from, ~to, ~FUN,
"CO", "ppm", "mg/m3", parts_to_mass_partial,
"NO", "ppb", "\u00b5g/m3", parts_to_mass_partial,
"O3", "ppb", "\u00b5g/m3", parts_to_mass_partial,
"NO2", "ppb", "\u00b5g/m3", parts_to_mass_partial,
"SO2", "ppb", "\u00b5g/m3", parts_to_mass_partial,
"CO", "mg/m3", "ppm", mass_to_parts_partial,
"NO", "\u00b5g/m3", "ppb", mass_to_parts_partial,
"O3", "\u00b5g/m3", "ppb", mass_to_parts_partial,
"NO2", "\u00b5g/m3", "ppb", mass_to_parts_partial,
"SO2", "\u00b5g/m3", "ppb", mass_to_parts_partial,
"NH3", "\u00b5g/m3", "ppb", mass_to_parts_partial,
"NH3", "ppb", "\u00b5g/m3", parts_to_mass_partial,
)
convert_set_conc_lookup(lookup)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.