Work with quantity units.
get_qty_units(q)
get_qty_units_with_label(q, label = names(q))quantities
text label to use with the units - single value or vector of the same length as q. By default uses the names of q, which only works if q is a list or data frame.
get_qty_units(): get units from a quantity, list of quantities or data frame (returns NA for objects/columns that are not quantities)
get_qty_units_with_label(): get units from a quantity, list of quantities or data frame, with a custom label in the format label [units]. Objects/columns that are not quantities simply return the label with out the [units] part.
Other quantity functions:
check_quantities,
make_qty_units_explicit(),
metric_scaling,
quantities,
quantity_data
# quantity units examples
qty(5000, "g") %>% get_qty_units()
#> [1] "kg"
x <- list(a = qty(5000, "g"), b = 42, c = qty(100, "mbar"))
x %>% get_qty_units()
#> a b c
#> "kg" NA "mbar"
# labels with units
get_qty_units_with_label(qty(0.1, "mM"), "concentration")
#> [1] "concentration [µM]"
# make labels with units for data frame columns
x <- data.frame(a = qty(1, "mg"), b = 2, c = qty(100, "mbar"))
get_qty_units_with_label(x)
#> a b c
#> "a [mg]" "b" "c [mbar]"
get_qty_units_with_label(x, "same label")
#> a b c
#> "same label [mg]" "same label" "same label [mbar]"