Get unit id, shortname, symbol or name of a value in accordance with StoX convention.

getUnit(
  value,
  property = c("id", "shortname", "symbol", "name"),
  unitTable = RstoxData::StoxUnits
)

Arguments

value

value to read unit from

property

the property of the unit that is to be returned (e.g. 'symbol' or 'name')

unitTable

formatted as StoxUnits

Value

the unit of value. <NA> if unit is not set

Examples

 dt <- data.table::data.table(weight=c(1000,1200))
 dt$weight <- setUnit(dt$weight, "mass-g")
 print(getUnit(dt$weight, "name"))
#> [1] "gram"