r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
175 stars 28 forks source link

Automatic promoting of unspecified units #234

Closed mattfidler closed 4 years ago

mattfidler commented 4 years ago

Hi,

Is there any way you can add a feature that promotes numbers to units on operations like +, -, ==, etc?

This way ggplot2 should work without the ggforce package (which doens't work currently). See:

https://github.com/thomasp85/ggforce/issues/190

An example would be:

a <- set_units(1, mg) + 2
#> 3 mg

It seems like a design choice, so I'm unsure if you think it is a good idea or not.

Enchufa2 commented 4 years ago

It's a design choice. Now, for convenience, we have:

set_units(3, m) * 2
#> 6 [m]

which means that we are treating numeric vectors as unitless quantities. Under this logic, you cannot sum any unit and a unitless quantity:

set_units(3, m) + set_units(2, 1)
#> Error: cannot convert 1 into m

Therefore, your example cannot work.