I have a script using number parameters with units. When printing messages to the log/user, I want the print to add the respective unit. I expected R to be smart enough to do so when doing:
library(units)
min_size = set_units(1200, "m^2")
print(paste0("Must be at least ", min_size))
# Prints: "Must be at least 1200"
# I want: "Must be at least 1200 m^2")
# ideally without explicitly adding " m^2", to avoid code inconsistency when changing units
print(paste0("Must be at least ", min_size, " m^2"))
The simple answer is to use
units(min_size)to get a printable representation of the unit.