%as% is a binary operator on strings with units in them
grapes-as-grapes.RdThe function calls the units utility and converts the string on the
left into the unit on the right, e.g.: "cm" %as% "inches", both
units can contain numbers. Any input that is accepted by the units
utility is acceptable, as long as it makes sense with the command
line arguments: units --strict --compact -1 "$originalUnit" "$targetUnit"
Value
a numeric value y: valoriginalUnit = ytargetUnit, the target unit is attached to the returned value, as a comment.
Examples
## needs `unit` utility (a system utility)
if (nzchar(Sys.which("units"))){
y <- "21 cm" %as% "inches"
y <- "12 nmol/L" %as% "mol/L"
print(comment(y))
y <- "12 mol/m^3" %as% "mmol/L"
} else {
message("The system utility 'units' is not installed, skipping example.")
}
#> Warning: The 'units' utility must be installed (system program, not R).
#> Warning: The 'units' utility must be installed (system program, not R).
#> NULL
#> Warning: The 'units' utility must be installed (system program, not R).