Learn R Programming

udunits2 (version 0.13.2.2)

ud.get.name: Retrieve the udunits name or symbol from the database for a given units string

Description

Retrieve the udunits name or symbol from the database for a given units string.

Usage

ud.get.name(unit.string)

Value

Returns a character string stating the udunits's name/symbol for the given unit, or an empty character string if the unit does not map to a name/symbol for the default character set. If the unit is unparseable, the function raises an error.

Arguments

unit.string

A character string which is parseable into a udunits compatible unit.

Author

James Hiebert hiebert@uvic.ca

Details

This function retrieves the udunits name or symbol from the udunits database and returns it. It uses the udunits functions ut_get_name and ut_get_symbol respectively.

References

Unidata's udunits reference: https://www.unidata.ucar.edu/software/udunits/ API guide for ut_get_name: https://docs.unidata.ucar.edu/udunits/current/udunits2lib.html#ut_get_name API guide for ut_get_symbol: https://docs.unidata.ucar.edu/udunits/current/udunits2lib.html#ut_get_symbol

Examples

Run this code
units.to.display <- c("celsius", # has no name, messed up symbol (maybe a bug in R?)
                      "kg",
                      "hr",      # has no symbol
                      "K",
                      "degrees",
                      "m",
                      "ohm")

for (u in units.to.display) {
  print(ud.get.name(u))
  print(ud.get.symbol(u))
}

Run the code above in your browser using DataLab