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 (=chemical substance) quantities use "mol"
as the base unit and "mole"
as a recognized alternative. All standard metric prefixes are supported.
qty(1, "mmole")
## <N (amount) in 'mmol'[1]>
## [1] 1
qty(1, "mmol")
## <N (amount) in 'mmol'[1]>
## [1] 1
qty(1, "pmol")
## <N (amount) in 'pmol'[1]>
## [1] 1
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
## <N (amount) in 'nmol'[1]>
## [1] 1
qty(1000, "pmol", scale_to_best_metric = FALSE) # keep the exact unit
## <N (amount) in 'pmol'[1]>
## [1] 1000
## <N (amount) in 'fmol'[3]>
## [1] 100 500 10000
Mass quantities use the gram "g"
as the base unit. All standard metric prefixes are supported.
qty(10000, "g")
## <m (mass) in 'kg'[1]>
## [1] 10
qty(5, "mg")
## <m (mass) in 'mg'[1]>
## [1] 5
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")
## <V (volume) in 'mL'[1]>
## [1] 42
qty(42, "ml")
## <V (volume) in 'mL'[1]>
## [1] 42
qty(2000, "nL")
## <V (volume) in 'µL'[1]>
## [1] 2
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")
## <T (temperature) in 'K'[1]>
## [1] 273.15
qty(32, "F")
## <T (temperature) in 'K'[1]>
## [1] 273.15
qty(273.15, "K")
## <T (temperature) in 'K'[1]>
## [1] 273.15
qty(273150, "mK")
## <T (temperature) in 'K'[1]>
## [1] 273.15
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")
## <P (pressure) in 'bar'[1]>
## [1] 1
qty(1000, "mbar")
## <P (pressure) in 'bar'[1]>
## [1] 1
qty(100, "% SP")
## <P (pressure) in 'bar'[1]>
## [1] 1
qty(1, "atm")
## <P (pressure) in 'bar'[1]>
## [1] 1.01325
qty(14.7, "psi")
## <P (pressure) in 'bar'[1]>
## [1] 1.01353
qty(760, "Torr")
## <P (pressure) in 'bar'[1]>
## [1] 1.01325
qty(760000, "mTorr")
## <P (pressure) in 'bar'[1]>
## [1] 1.01325
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")
## <MW (molecular weight) in 'g/mol'[1]>
## [1] 257
qty(4.2, "kg/mol")
## <MW (molecular weight) in 'kg/mol'[1]>
## [1] 4.2
qty(4.2, "kDa")
## <MW (molecular weight) in 'kg/mol'[1]>
## [1] 4.2
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 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")
## <C (molarity concentration) in 'mM'[1]>
## [1] 5
qty(5, "mmol/L")
## <C (molarity concentration) in 'mM'[1]>
## [1] 5
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")
## <C (mass concentration) in 'mg/L'[1]>
## [1] 5
qty(5, "mg/l")
## <C (mass concentration) in 'mg/L'[1]>
## [1] 5
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")
## <S (gas solubility) in 'mM/bar'[1]>
## [1] 5
qty(5, "mM/atm")
## <S (gas solubility) in 'mM/bar'[1]>
## [1] 4.934616