Learn R Programming

units (version 0.4-5)

install_conversion_constant: Install a function for conversion between user-defined units.

Description

Tells the units package how to convert between units that have a linear relationship, i.e. can be related on the form \(y = \alpha x\).

Usage

install_conversion_constant(from, to, const)

Arguments

from

String for the symbol of the unit being converted from.

to

String for the symbol of the unit being converted to.

const

The constant \(\alpha\) in the conversion.

Details

This function handles the very common case where units are related through a linear function, that is, you can convert from one to the other as \(y = \alpha x\). Using this function, you specify that you can go from values of type from to values of type to by first multiplying a constant and then adding an offset. The function then automatically installs that conversion and the invers \(x = y/\alpha\).

For a more general conversion mechanism, see install_conversion_function.

See Also

install_conversion_function

Examples

Run this code
# NOT RUN {
apples <- 2 * make_unit("apple")
oranges <- 1 * make_unit("orange")
# one orange is worth two apples
install_conversion_constant("orange", "apple", 2)
apples + oranges
oranges + apples

# }

Run the code above in your browser using DataLab