r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
175 stars 28 forks source link

Adding molarity? #362

Closed sardnar closed 11 months ago

sardnar commented 11 months ago

Hi, Thank you for this cool work. I have a request for adding molarity units. molarity is a chemical unit for concentration. 1M = mol/L. 1uM = 1micro mol /L ... etc. I think this could be applied by the symbols of M, mM, uM, nM ... etc.

A tough part however is that moles is a standardized quantity of weight by molecular mass. So 1 mol of calcium = 40 gms.

Is some extension like that possible?

Enchufa2 commented 11 months ago

We rely on udunits2, and molarity is not defined in that database, but we provide a mechanism to extend the database with new units. In this case, you need:

install_unit("M", "1 mol/L", "molarity")

and you are good to go.

About moles of substances, it's a complicated problem, yes. There's an ongoing effort to address this in a separate package, see https://github.com/r-quantities/substances/issues/1.

sardnar commented 11 months ago

Thanks! When I follow this discussions, I can find a talk about install_conversion_constant() function in units package. However, I can't find it exported?

Enchufa2 commented 11 months ago

That's an old function, long gone. install_unit is the replacement.