quantity_data: Get quantity data

quantity_dataR Documentation

Get quantity data

Description

Get data from quantity objects including their values (equivalent of as.numeric) and text representations (equivalent of as.character).

Usage

get_qty_value(x, unit = NULL)

## S3 method for class 'mk_quantity'
as.double(x, unit = NULL, ...)

get_qty_text(x, unit = get_qty_units(x), signif = 5)

## S3 method for class 'mk_quantity'
as.character(x, unit = get_qty_units(x), signif = 5, ...)

get_qty_text_each(x, signif = 5)

Arguments

x

quantities

unit

which units to retrieve quantity data in (by default the unit the quantity is in)

...

additional parameters for the generics

signif

number of significant digits for printing the quantity

Functions

  • get_qty_value(): get the value of a quantity in the desired unit. By default returns the quantity in the units it is in. Functionally equivalent to as.numeric and as.double.

  • as.double(mk_quantity): S3 extension of as.numeric and as.double with optional unit argument

  • get_qty_text(): get the value of the quantity in the desired unit as a text string with the unit appended. Functionally equivalent to as.character.

  • as.character(mk_quantity): S3 implementation of as.character with optional unit and signif argument

  • get_qty_text_each(): get each value of a quantity in the best metric unit with the unit appended. Note that if a value is zero, it will use the unit of the next smallest value for this number.

See Also

Other quantity functions: check_quantities, make_qty_units_explicit(), metric_scaling, quantities, quantity_units

Examples

# quantity value examples
qty(0.1, "g") %>% get_qty_value()
qty(0.1, "g") %>% get_qty_value("g")
qty(0, "C") %>% get_qty_value("F")
qty(760, "Torr") %>% get_qty_value("atm")
qty(760, "Torr") %>% as.numeric("atm")

# quantity text examples
qty(0.1, "g") %>% get_qty_text()
qty(0.1, "g") %>% get_qty_text("g")
qty(0:10, "C") %>% get_qty_text("F")
qty(760, "Torr") %>% get_qty_text("atm")
qty(760, "Torr") %>% as.character("atm")

# each quantity text example
qty(c(0, 0.1, 10, 1000), "mg") %>% get_qty_text() # 0.1mg 10mg 1000mg
qty(c(0, 0.1, 10, 1000), "mg") %>% get_qty_text_each() # 0ug 100ug 10mg 1g

sebkopf/chemtools documentation built on Aug. 1, 2023, 2:36 a.m.