These arithmetic operators for quantities in mediachemtools 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.

qty == qty, qty != qty, qty < qty, qty <= qty, qty > qty, qty >= qty

qty + qty, qty - qty

qty / qty

qty / number

qty * number

amount / volume = molarity, amount / molarity = volume, molarity * volume = amount

mass / volume = density, mass / density = volume, density * volume = mass

mass / molecular mass = amount, mass / amount = molecular mass, amount * molecular mass = mass

molarity / pressure = solubility, solubility * pressure = molarity, molarity / solubility = pressure

Details

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

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).

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.

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

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

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

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

mass / density divide a mass by a density to create a volume.

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

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

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

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

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

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

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

Examples

qty(1, "g") == qty(1000, "mg") # TRUE
#> [1] TRUE
qty(2, "mg") < qty(5, "ng") # FALSE
#> [1] FALSE
qty(1000, "mg") + qty(999, "g") # 1 kg
#> Mass [kg] #> [1] 1
qty(5, "mg") / qty(1, "g") # 0.005
#> [1] 0.005
qty(5, "mg") / 1e6 # 5 ng
#> Mass [ng] #> [1] 5
qty(5, "mg") * 1e6 # 5 kg
#> Mass [kg] #> [1] 5
qty(5, "nmol") / qty(50, "mL") # 100 nM
#> Molarity [nM] #> [1] 100
qty(5, "nmol") / qty(100, "nM") # 50 mL
#> Volume [mL] #> [1] 50
qty(100, "nM") * qty(50, "mL") # 5 nmol
#> Amount [nmol] #> [1] 5
qty(5, "ng") / qty(50, "mL") # 100 ng/L
#> Density [ng/L] #> [1] 100
qty(5, "ng") / qty(100, "ng/L") # 50 mL
#> Volume [mL] #> [1] 50
qty(100, "ng/L") * qty(50, "mL") # 5 ng
#> Mass [ng] #> [1] 5
qty(10, "g") / qty (50, "g/mol") # 200 nmol
#> Amount [mmol] #> [1] 200
qty(10, "g") / qty(200, "mmol") # 50 g/mol
#> MolecularMass [g/mol] #> [1] 50
qty(200, "mmol") * qty (50, "g/mol") # 10 g
#> Mass [g] #> [1] 10
qty(10, "mM") / qty(200, "mbar") # 50 mM/bar
#> Solubility [mM/bar] #> [1] 50
qty(10, "mM") / qty(50, "mM/bar") # 200 mbar
#> Pressure [mbar] #> [1] 200
qty(50, "mM/bar") * qty (200, "mbar") # 10 mM
#> Molarity [mM] #> [1] 10