util.units {CHNOSZ}R Documentation

Functions to Convert Units


These functions convert values between units and set the user's preferred units.


  P.units(units = NULL)
  T.units(units = NULL)
  E.units(units = NULL)
  convert(value, units, T = 298.15, P = 1, pH = 7, logaH2O = 0)



character, name of units to set or convert to/from


numeric, value(s) to be converted


numeric, temperature (Kelvin), used in ‘⁠G⁠’-‘⁠logK⁠’, ‘⁠pe⁠’-‘⁠Eh⁠’ and ‘⁠logfO2⁠’-‘⁠E0⁠’ conversions


numeric, pressure (bar), used in ‘⁠logfO2⁠’-‘⁠E0⁠’ conversions


numeric, pH, used in ‘⁠logfO2⁠’-‘⁠E0⁠’ conversions


numeric, logarithm of activity of water, used in ‘⁠logfO2⁠’-‘⁠E0⁠’ conversions


The units settings are used by subcrt, affinity, and diagram to accept input in or convert output to the units desired by the user. The settings, which can be queried or changed with T.units, E.units and P.units, refer to the units of temperature (C or K), energy (J or cal), and pressure (bar or MPa). (The first value in each of those pairs refers to the default units).

The actual units conversions are handled by convert, through which values are transformed into destination units (names not case sensitive). The possible conversions and settings for the units argument are shown in the following table. Note that ‘⁠Eh⁠’ and ‘⁠E0⁠’ both stand for the value of Eh (oxidation-reduction potential in volts); they have different names so that one can choose to convert between Eh and either ‘⁠pe⁠’ or ‘⁠logfO2⁠’.

property units setting of units argument
temperature °C, K C, K
pressure bar, MPa bar, MPa
energy cal, J cal, J
energy J, cm^3 bar joules, cm3bar
energy J, [none] G, logK
oxidation potential volt, [none] Eh, pe
oxidation potential volt, [none] E0, logfO2

Another use of the function is to convert the results from solubility into parts per billion, million, or thousand. These destination units are specified by ‘⁠ppb⁠’, ‘⁠ppm⁠’, or ‘⁠ppt⁠’. Additionally, the logarithms can be chosen with ‘⁠logppb⁠’, ‘⁠logppm⁠’, and ‘⁠logppt⁠’. See demo("contour") and demo("sphalerite") for examples.


## Direct usage of convert
# Temperature (Kelvin) to degrees C
convert(273.15, "C")
# Temperature (degrees C) to Kelvin
convert(100, "K")
# Gibbs energy (J mol-1) to/from logK
convert(1000, "logK")		
convert(1000, "logK", T = 373.15)
convert(1, "G") 
# Eh (volt) to pe 
convert(-1, "pe")		
convert(-1, "pe", T = 373.15)
# logfO2 to E0 (volt)
convert(-80, "E0")             
convert(-80, "E0", pH = 5)
convert(-80, "E0", pH = 5, logaH2O = -5)
# Convert from calories to Joules
convert(1, "J")    # 1 cal = 4.184 J
# Convert from Joules to calories
convert(1, "cal")  # 1 J = 0.239 cal
# Convert cm3bar to Joules
convert(10, "joules") # 10 cm3.bar = 1 J

## Setting the units
# Make K the units for temperature arguments to subcrt() and affinity()
# Return to default - degrees C

[Package CHNOSZ version 2.0.0 Index]