convert_units: A safe version of 'measurements::conv_unit()'.

Description Usage Arguments Value See Also Examples

Description

Unlike measurements::conv_unit() this function doesn't fail if it can't convert a unit – instead it outputs NA.

Usage

1
convert_units(x, from, to, quietly = FALSE)

Arguments

x

a numeric vector giving the measurement value in its original units.

from

the unit in which the measurement was made.

to

the unit to which the measurement is to be converted.

quietly

TRUE suppresses warning.

Value

As in measurements::conv_unit() if possible, or NA.

See Also

Other helpers: valid_units

Examples

1
2
3
4
5
6
7
8
9
convert_units(c(1, NA), from = "cm", to = "m")
# Same
measurements::conv_unit(c(1, NA), from = "cm", to = "m")

# Passes
convert_units(c(1, 10), from = "cm", to = c("m", "bad"))
convert_units(c(1, 10), from = "cm", to = c("m", "bad"), quietly = TRUE)
# Errs
try(measurements::conv_unit(c(1, 10), from = "cm", to = c("m", "bad")))

forestgeo/fgeo.biomass documentation built on June 8, 2019, 10:47 p.m.