These arithmetic operators for quantities in microbialkitchen keep track of units in standard operations (i.e. they ALL take the SI prefix into consideration). Also note that all operations that result in a new quantity object automatically scale the new value using best_metric.

Arguments

qty

quantity

number

regular number

Details

qty ==, !=, <, <=, >, >= qty allows the comparison of quantities that are the same type (e.g. all mass).

qty / number divide quantity by a plain number. Returns the quantity automatically rescaled to the best metric.

qty * number multiply a quantity by a plain number (either way around is valid). Returns the quantity automatically rescaled to the best metric.

qty +- qty allows the addition/subtraction of quantities that are the same type (e.g. all mass). Note that this operation also scales the new value using best_metric.

qty / qty divide quantities of the same type. Returns plain numeric (i.e. the units are divided out).

amount / volume divide an amount by a volume to create a molarity (concentration).

amount / molarity divide an amount by a molarity concentration to create a volume.

molarity * volume multiply a molarity concentration by a volume (or the other way around) to create an amount.

mass / volume divide a mass by a volume to create mass concentration (density).

mass / density divide a mass by a mass concentration (density) to create a volume.

density * volume multiply a mass concentration (density) by a volume (or the other way around) to create a mass.

mass / MW divide a mass by a molecular weight to create an amount (mols).

mass / amount divide a mass by an amount (mols) to create a molecular weight.

amount * MW multiply an amount (mols) by a molecular weight to create a mass.

molarity / pressure divide a concentration by pressure to create a gas solubility (M/bar).

molarity / solubility divide a molarity (M) by a gas solubility (M/bar) to get partial pressure (bar)

solubility * pressure multiply a gas solubility (M/bar) by pressure (bar) to create molarity (M)

Examples

qty(1, "g") == qty(1000, "mg", scale_to_best_metric = FALSE) # TRUE
#> [1] TRUE
qty(2, "mg") < qty(5, "ng") # FALSE
#> [1] FALSE
qty(5, "mg") / 1e6 # 5 ng
#> <m (mass) in 'ng'[1]> #> [1] 5
qty(5, "mg") * 1e6 # 5 kg
#> <m (mass) in 'kg'[1]> #> [1] 5
qty(1, "mg") + qty(999.999, "g") # 1 kg
#> <m (mass) in 'kg'[1]> #> [1] 1
qty(5, "mg") / qty(1, "g") # 0.005
#> [1] 0.005
qty(5, "nmol") / qty(50, "mL") # 100 nM
#> <C (molarity concentration) in 'nM'[1]> #> [1] 100
qty(5, "nmol") / qty(100, "nM") # 50 mL
#> <V (volume) in 'mL'[1]> #> [1] 50
qty(100, "nM") * qty(50, "mL") # 5 nmol
#> <N (amount) in 'nmol'[1]> #> [1] 5
qty(5, "ng") / qty(50, "mL") # 100 ng/L
#> <C (mass concentration) in 'ng/L'[1]> #> [1] 100
qty(5, "ng") / qty(100, "ng/L") # 50 mL
#> <V (volume) in 'mL'[1]> #> [1] 50
qty(100, "ng/L") * qty(50, "mL") # 5 ng
#> <m (mass) in 'ng'[1]> #> [1] 5
qty(10, "g") / qty (50, "g/mol") # 200 mmol
#> <N (amount) in 'mmol'[1]> #> [1] 200
qty(10, "g") / qty(200, "mmol") # 50 g/mol
#> <MW (molecular weight) in 'g/mol'[1]> #> [1] 50
qty(200, "mmol") * qty (50, "g/mol") # 10 g
#> <m (mass) in 'g'[1]> #> [1] 10
qty(10, "mM") / qty(200, "mbar") # 50 mM/bar
#> <S (gas solubility) in 'mM/bar'[1]> #> [1] 50
qty(10, "mM") / qty(50, "mM/bar") # 200 mbar
#> <P (pressure) in 'mbar'[1]> #> [1] 200
qty(50, "mM/bar") * qty (200, "mbar") # 10 mM
#> <C (molarity concentration) in 'mM'[1]> #> [1] 10