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(MediaChemTools) # load the library

# 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") %>% print()
## Amount [mmol]
## [1] 1
qty(1, "mmol") %>% print()
## Amount [mmol]
## [1] 1
qty(1, "pmol") %>% print()
## Amount [pmol]
## [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") %>% print() # automatic metric scaling
## Amount [nmol]
## [1] 1
qty(1000, "pmol", scale_to_best_metric = FALSE) %>% print() # keep the exact unit
## Amount [pmol]
## [1] 1000
qty(c(0.1, 0.5, 10), "pmol") %>% print() # automatic scaling to median
## Amount [fmol]
## [1]   100   500 10000

# Mass

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

qty(10000, "g") %>% print()
## Mass [kg]
## [1] 10
qty(5, "mg") %>% print()
## Mass [mg]
## [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") %>% print()
## Volume [mL]
## [1] 42
qty(42, "ml") %>% print()
## Volume [mL]
## [1] 42
qty(2000, "nL") %>% print()
## Volume [µL]
## [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") %>% print()
## Temperature [K]
## [1] 273.15
qty(32, "F") %>% print()
## Temperature [K]
## [1] 273.15
qty(273.15, "K") %>% print()
## Temperature [K]
## [1] 273.15
qty(273150, "mK") %>% print()
## Temperature [K]
## [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") %>% print()
## Pressure [bar]
## [1] 1
qty(1000, "mbar") %>% print()
## Pressure [bar]
## [1] 1
qty(100, "% SP") %>% print()
## Pressure [bar]
## [1] 1
qty(1, "atm") %>% print()
## Pressure [bar]
## [1] 1.01325
qty(14.7, "psi") %>% print()
## Pressure [bar]
## [1] 1.01353
qty(760, "Torr") %>% print()
## Pressure [bar]
## [1] 1.01325
qty(760000, "mTorr") %>% print()
## Pressure [bar]
## [1] 1.01325

# Molecular Mass

Molecular mass (sometimes also called molar mass or molecular weight) 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") %>% print()
## MolecularMass [g/mol]
## [1] 257
qty(4.2, "kg/mol") %>% print()
## MolecularMass [kg/mol]
## [1] 4.2
qty(4.2, "kDa") %>% print()
## MolecularMass [kg/mol]
## [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 masses (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") %>% print()
## Molarity [mM]
## [1] 5
qty(5, "mmol/L") %>% print()
## Molarity [mM]
## [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") %>% print()
## Density [mg/L]
## [1] 5
qty(5, "mg/l") %>% print()
## Density [mg/L]
## [1] 5

# Solubility

Solubility quantities (i.e. 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") %>% print()
## Solubility [mM/bar]
## [1] 5
qty(5, "mM/atm") %>% print()
## Solubility [mM/bar]
## [1] 4.934616