All quantity data types are accessible via the universal qty function. The qty function always takes a numeric value (either single value or vector) and a unit that must match one of the supported units. For al available quantities, the standard SI units and metric prefixes are supported as well as a few frequently used non-SI units (e.g. atm for pressure, C for temperature). However, non-standard units are automatically converted to the corresponding SI unit. Additionally, the qty function takes the optional argument scale_to_best_metric which determines whether the values should be automatically scaled to the most appropriate metric prefix (e.g. 10 mg instead of 0.01 g). By default, this is done (i.e. scale_to_best_metric = TRUE). If the quantity is a vector, the best scaling is determined based on the median of all values.

Once familiar with the quantities supported by this package, take a look at the operations vignette to see what you can do with them.

library(microbialkitchen) # load the library
## 
## Attaching package: 'microbialkitchen'
## The following object is masked from 'package:base':
## 
##     as.factor

Amount

Amount (=chemical substance) quantities use "mol" as the base unit and "mole" as a recognized alternative. All standard metric prefixes are supported.

qty(1, "mmole")
## <mk_amount[1]>
## [1] 1
qty(1, "mmol")
## <mk_amount[1]>
## [1] 1
qty(1, "pmol")
## <mk_amount[1]>
## [1] 1

Metric scaling example

By default quantities are scaled to the most sensible metric prefix (of the median for vector quantities), unless explicitly instructed not to. For more details on scaling, see the units & metric scaling section of the operations vignette.

qty(1000, "pmol") # automatic metric scaling
## <mk_amount[1]>
## [1] 1
qty(1000, "pmol", scale_to_best_metric = FALSE) # keep the exact unit
## <mk_amount[1]>
## [1] 1000
qty(c(0.1, 0.5, 10), "pmol") # automatic scaling to median
## <mk_amount[3]>
## [1]   100   500 10000

Mass

Mass quantities use the gram "g" as the base unit. All standard metric prefixes are supported.

qty(10000, "g")
## <mk_mass[1]>
## [1] 10
qty(5, "mg")
## <mk_mass[1]>
## [1] 5

Volume

Volume quantities use the SI-accepted litre "L" as the base unit because of its common use in chemical applications (as compared to the equivalent dm\(^3\) or base unit m\(^3\)). Lower case "l" is also recognized. All standard metric prefixes are supported.

qty(42, "mL")
## <mk_volume[1]>
## [1] 42
qty(42, "ml")
## <mk_volume[1]>
## [1] 42
qty(2000, "nL")
## <mk_volume[1]>
## [1] 2

Temperature

Temperature quantities use the SI unit Kelvin ("K") but can be generated from the alternative units Celsius ("C") and Fahrenheit ("F"). For example, the following statements all generate the same temperature object. Note that although rarely used in chemical applications for culturing, metric prefixes are supported for the "K" base unit.

qty(0, "C")
## <mk_temperature[1]>
## [1] 273.15
qty(32, "F")
## <mk_temperature[1]>
## [1] 273.15
qty(273.15, "K")
## <mk_temperature[1]>
## [1] 273.15
qty(273150, "mK")
## <mk_temperature[1]>
## [1] 273.15

Pressure

Pressure quantities use the non-SI but metric unit "bar" as base unit (1 bar = 100,000 Pa) because of its more common use in chemical and culturing applications. However, pressure quantities can also be generated from the SI unit "Pa" as well as the common non-metric units "atm", "psi", "Torr", "mTorr" and "% SP" (% of standard pressure = % of 1 bar) which are all automatically converted to bar. All pressure quantities are absolute pressures (i.e. technically psi is psiA, not relative to atmospheric). All standard metric prefixes are supported for the bar base unit.

qty(1, "bar")
## <mk_pressure[1]>
## [1] 1
qty(1000, "mbar")
## <mk_pressure[1]>
## [1] 1
qty(100, "% SP")
## <mk_pressure[1]>
## [1] 1
qty(1, "atm")
## <mk_pressure[1]>
## [1] 1.01325
qty(14.7, "psi")
## <mk_pressure[1]>
## [1] 1.01353
qty(760, "Torr")
## <mk_pressure[1]>
## [1] 1.01325
qty(760000, "mTorr")
## <mk_pressure[1]>
## [1] 1.01325

Molecular Weight

Molecular weight (sometimes also called molar mass or molecular mass) quantities use gram / mole "g/mol" as the base unit and the SI-accepted Dalton "Da" as a recognized alternative (1 Da = 1 g/mol). All standard metric prefixes are supported.

qty(257, "g/mol")
## <mk_molecular_weight[1]>
## [1] 257
qty(4.2, "kg/mol")
## <mk_molecular_weight[1]>
## [1] 4.2
qty(4.2, "kDa")
## <mk_molecular_weight[1]>
## [1] 4.2

Concentration

The two most common concentration measurements in culturing and media chemistry are amount-based and mass-based concentrations, i.e. amount/volume (molarity) and mass/volume (~density). Both are supported quantities and can be interconverted from one to the other using molecular weightes (see the arithmetic section of the operations vignette for details).

Amount-based (molarity)

Amount-based concentration quantities use molar concentration "M" as the base unit with the more explicit mol/L as a recognized alternative (1 mol/L = 1 M). All standard metric prefixes are supported.

qty(5, "mM")
## <mk_molarity_concentration[1]>
## [1] 5
qty(5, "mmol/L")
## <mk_molarity_concentration[1]>
## [1] 5

Weight-based (density)

Weight-based concentration quantities use volumetric mass density "g/L" as the base unit. These are not densities in the solid matter or pure liquid sense (\(\rho\)) but rather solute densities in a solution. All standard metric prefixes are supported.

qty(5, "mg/L")
## <mk_mass_concentration[1]>
## [1] 5
qty(5, "mg/l")
## <mk_mass_concentration[1]>
## [1] 5

Gas Solubility

Gas solubility quantities (e.g. Henry’s law solubility constants) use the non-SI but metric unit "M/bar" as base unit. However, solubility quantities can also be generated from the common non-metric unit "M/atm", which is automatically converted to M/bar. All standard metric prefixes are supported in the numerator for both "M/bar" and "M/atm".

qty(5, "mM/bar")
## <mk_gas_solubility[1]>
## [1] 5
qty(5, "mM/atm")
## <mk_gas_solubility[1]>
## [1] 4.934616