Description Usage Arguments Details Examples
Converts a character string to units
. If available, unit names are replaced by the corresponding symbol.
1 | parse_unit(string)
|
string |
(character) Unit string to parse. |
The string may only contain unit names, numeric exponents, and operators "/", "*", "^", "(", and ")". Spaces between unit names are interpreted as "*". This includes the following standard formats:
Product power form (e.g. "kg m2 s-1")
Arithmetic expression (e.g. "kg * (m^2 / s)")
... or a mix of both (e.g. "kg1 (m^2 s-1)")
Unlike parse_unit
:
Input must be a length-one character vector.
Unknown units throw an error (via ud.is.parseable
).
Unit names are replaced by their symbol (via ud.get.symbol
). This is a limitation of evaluating the constructed expression against ud_units
.
An empty string results in units::as.units(1, value = units::unitless)
rather than units::make_unit("")
.
For a list of supported units and their notation, see the UDUNITS-2 Units Database.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | parse_unit("m/s")
parse_unit("(m)/(s)")
parse_unit("m s-1")
parse_unit("meters/seconds")
parse_unit("meters seconds-1")
parse_unit("kg * (m^2 / s^3)")
parse_unit("kg (m^2 / s^3)")
parse_unit("kg m2 s-3")
parse_unit("in")
parse_unit("in/s")
parse_unit("°")
parse_unit("µm/s")
parse_unit("mm")
parse_unit("H2O+1 m1 s-1")
## Not run:
parse_unit("unknown")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.