Debian Codegraph @

man/install_unit.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/user_conversion.R
3 \name{install_unit}
4 \alias{install_unit}
5 \alias{remove_unit}
6 \title{Define or remove units}
7 \usage{
8 install_unit(symbol = character(0), def = character(0),
9 name = character(0))
10
11 remove_unit(symbol = character(0), name = character(0))
12 }
13 \arguments{
14 \item{symbol}{a vector of symbols to be installed/removed.}
15
16 \item{def}{either \itemize{
17 \item an empty definition, which defines a new base unit;
18 \item \code{"unitless"}, which defines a new dimensionless unit;
19 \item a relationship with existing units (see details for the syntax).
20 }}
21
22 \item{name}{a vector of names to be installed/removed.}
23 }
24 \description{
25 Installing new symbols and/or names allows them to be used in \code{as_units},
26 \code{make_units} and \code{set_units}. Optionally, a relationship can be
27 defined between such symbols/names and existing ones (see details and examples).
28 }
29 \details{
30 At least one symbol or name is expected, but multiple symbols and/or names
31 can be installed (and thus mapped to the same unit) or removed at the same
32 time. The \code{def} argument enables arbitrary relationships with existing
33 units using UDUNITS-2 syntax:
34 \tabular{llll}{
35 \strong{String Type} \tab \strong{Using Names} \tab \strong{Using Symbols}
36 \tab \strong{Comment}\cr
37 Simple \tab meter \tab m \tab \cr
38 Raised \tab meter^2 \tab m2 \tab
39 higher precedence than multiplying or dividing\cr
40 Product \tab newton meter \tab N.m \tab \cr
41 Quotient \tab meter per second \tab m/s \tab \cr
42 Scaled \tab 60 second \tab 60 s \tab \cr
43 Prefixed \tab kilometer \tab km \tab \cr
44 Offset \tab kelvin from 273.15 \tab K @ 273.15 \tab
45 lower precedence than multiplying or dividing\cr
46 Logarithmic \tab lg(re milliwatt) \tab lg(re mW) \tab
47 "lg" is base 10, "ln" is base e, and "lb" is base 2\cr
48 Grouped \tab (5 meter)/(30 second) \tab (5 m)/(30 s) \tab
49 }
50 The above may be combined, e.g., \code{"0.1 lg(re m/(5 s)^2) @ 50"}.
51 You may also look at the \code{<def>} elements in the units database to see
52 examples of string unit specifications.
53 }
54 \examples{
55 # define a fortnight
56 install_unit("fn", "2 week", "fortnight")
57 year <- as_units("year")
58 set_units(year, fn) # by symbol
59 set_units(year, fortnight) # by name
60 # clean up
61 remove_unit("fn", "fortnight")
62
63 # working with currencies
64 install_unit("dollar")
65 install_unit("euro", "1.22 dollar")
66 install_unit("yen", "0.0079 euro")
67 set_units(as_units("dollar"), yen)
68 # clean up
69 remove_unit(c("dollar", "euro", "yen"))
70
71 # an example from microbiology
72 cfu_symbols <- c("CFU", "cfu")
73 cfu_names <- c("colony_forming_unit", "ColonyFormingUnit")
74 install_unit("cell")
75 install_unit(cfu_symbols, "3.4 cell", cfu_names)
76 cell <- set_units(2.5e5, cell)
77 vol <- set_units(500, ul)
78 set_units(cell/vol, "cfu/ml")
79 set_units(cell/vol, "CFU/ml")
80 set_units(cell/vol, "colony_forming_unit/ml")
81 set_units(cell/vol, "ColonyFormingUnit/ml")
82 # clean up
83 remove_unit(c("cell", cfu_symbols), cfu_names)
84
85 }