Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
122 lines (87 sloc) 5.66 KB
title: "Quantities"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
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](operations.html) 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()
qty(1, "mmol") %>% print()
qty(1, "pmol") %>% print()
## 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](operations.html#units-metric-scaling) of the [operations vignette](operations.html).
qty(1000, "pmol") %>% print() # automatic metric scaling
qty(1000, "pmol", scale_to_best_metric = FALSE) %>% print() # keep the exact unit
qty(c(0.1, 0.5, 10), "pmol") %>% print() # automatic scaling to median
# Mass
Mass quantities use the gram `"g"` as the base unit. All standard metric prefixes are supported.
qty(10000, "g") %>% print()
qty(5, "mg") %>% print()
# 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()
qty(42, "ml") %>% print()
qty(2000, "nL") %>% print()
# 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()
qty(32, "F") %>% print()
qty(273.15, "K") %>% print()
qty(273150, "mK") %>% print()
# 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()
qty(1000, "mbar") %>% print()
qty(100, "% SP") %>% print()
qty(1, "atm") %>% print()
qty(14.7, "psi") %>% print()
qty(760, "Torr") %>% print()
qty(760000, "mTorr") %>% print()
# 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()
qty(4.2, "kg/mol") %>% print()
qty(4.2, "kDa") %>% print()
# 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](operations.html#units-metric-scaling) of the [operations vignette](operations.html) 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()
qty(5, "mmol/L") %>% print()
## 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()
qty(5, "mg/l") %>% print()
# 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()
qty(5, "mM/atm") %>% print()
You can’t perform that action at this time.