Some udunits2 utilities are exposed to the user. These functions are useful for checking whether units are convertible or converting between units without having to create units objects.
Value
ud_are_convertible
returns TRUE
if both units exist and are convertible,
FALSE
otherwise.
ud_convert
returns a numeric vector with x
converted to new unit.
Examples
ud_are_convertible("m", "km")
#> [1] TRUE
ud_convert(100, "m", "km")
#> [1] 0.1
a <- set_units(1:3, m/s)
ud_are_convertible(units(a), "km/h")
#> [1] TRUE
ud_convert(1:3, units(a), "km/h")
#> [1] 3.6 7.2 10.8
ud_are_convertible("degF", "degC")
#> [1] TRUE
ud_convert(32, "degF", "degC")
#> [1] 3.552714e-14