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
#> <mk_mass[1]>
#> [1] 5
qty(5, "mg") * 1e6 # 5 kg
#> <mk_mass[1]>
#> [1] 5
qty(1, "mg") + qty(999.999, "g") # 1 kg
#> <mk_mass[1]>
#> [1] 1
qty(5, "mg") / qty(1, "g") # 0.005
#> [1] 0.005
qty(5, "nmol") / qty(50, "mL") # 100 nM
#> <mk_molarity_concentration[1]>
#> [1] 100
qty(5, "nmol") / qty(100, "nM") # 50 mL
#> <mk_volume[1]>
#> [1] 50
qty(100, "nM") * qty(50, "mL") # 5 nmol
#> <mk_amount[1]>
#> [1] 5
qty(5, "ng") / qty(50, "mL") # 100 ng/L
#> <mk_mass_concentration[1]>
#> [1] 100
qty(5, "ng") / qty(100, "ng/L") # 50 mL
#> <mk_volume[1]>
#> [1] 50
qty(100, "ng/L") * qty(50, "mL") # 5 ng
#> <mk_mass[1]>
#> [1] 5
qty(10, "g") / qty (50, "g/mol") # 200 mmol
#> <mk_amount[1]>
#> [1] 200
qty(10, "g") / qty(200, "mmol") # 50 g/mol
#> <mk_molecular_weight[1]>
#> [1] 50
qty(200, "mmol") * qty (50, "g/mol") # 10 g
#> <mk_mass[1]>
#> [1] 10
qty(10, "mM") / qty(200, "mbar") # 50 mM/bar
#> <mk_gas_solubility[1]>
#> [1] 50
qty(10, "mM") / qty(50, "mM/bar") # 200 mbar
#> <mk_pressure[1]>
#> [1] 200
qty(50, "mM/bar") * qty (200, "mbar") # 10 mM
#> <mk_molarity_concentration[1]>
#> [1] 10