convert_val {respR} | R Documentation |
Convert values of temperature, volume, mass, area, and atmospheric pressure to different units
Description
This is a basic function that converts values of temperature, volume, mass,
area, and atmospheric pressure to different units. This can be useful in
convert_DO()
, convert_rate()
, and convert_rate.ft()
where some inputs
must be in specific units (e.g. temperature in °C, atmospheric pressure in
bar, area in m2). See Examples.
Usage
convert_val(x, from = NULL, to = NULL)
Arguments
x |
numeric value or vector. Values to be converted to a different unit. |
from |
string. Unit of the original values. |
to |
string. Unit to be converted to. These defaults are applied if left
|
Details
Note the type of unit does not need to be specified. The function will
automatically recognise it using the from
unit.
If the 'to'
input is left NULL
, the following defaults are applied
depending on the unit type of the from
input:
volume:
"L"
temperature:
"C"
mass:
"kg"
area:
"m2"
pressure:
"bar"
A fuzzy string matching algorithm is used to accept different unit formatting
styles. For example, "msq"
"m2"
, "M2"
, "sqm"
are all parsed as metres
squared of area.
Accepted Units
Temperature:
-
"C"
,"K"
,"F"
Pressure:
-
"kPa"
,"hPa"
,"Pa"
,"ubar"
,"mbar"
,"bar"
,"Torr"
,"atm"
(note, this is standard atmospheres).
Volume:
-
"uL"
,"mL"
,"L"
Mass:
-
"ug"
,"mg"
,"g"
,"kg"
Area:
-
"mm2"
,"cm2"
,"m2"
,"km2"
More
For additional help, documentation, vignettes, and more visit the respR
website at https://januarharianto.github.io/respR/
Value
Output is a numeric vector of converted values.
Examples
# Convert volume
convert_val(10, "ml", "L")
convert_val(10:15, "ml", "L")
# Convert temperature
convert_val(-273.15, "C", "K")
convert_val(-40, "C", "F")
convert_val(c(2,4,6,8), "C", "F")
# Convert pressure
convert_val(1, "atm", "bar")
convert_val(1010, "hpa", "bar")
convert_val(735, "torr", "kpa")
# Convert area
convert_val(100, "cm2", "m2")
convert_val(10000, "mm2", "cm2")
# Convert mass
convert_val(200, "g", "kg")
convert_val(10000, "ug", "mg")
# Use directly in a respR function which requires inputs to be
# in a specific unit. For example, in convert_rate() pressure
# must be in 'bar' and respirometer volume in 'L'.
# Here, we know chamber volume is 200 ml, and pressure measured in mbar.
x <- suppressWarnings(inspect(urchins.rd, 1, 2))
rate <- calc_rate(x, from = 20, to = 30)
convert_rate(rate,
oxy.unit = "ml/l",
time.unit = "min",
output.unit = "mg/h",
volume = convert_val(200, "ml", "L"),
S = 35,
t = 15,
P = convert_val(1010, "mbar", "bar"))
# Note, the default 'to' units are set to those respR requires in
# these functions ('L' and 'bar' here), so do not necessarily need
# to be specified:
convert_rate(rate,
oxy.unit = "ml/l",
time.unit = "min",
output.unit = "mg/h",
volume = convert_val(200, "ml"),
S = 35,
t = 15,
P = convert_val(1010, "mbar"))