r-quantities / units

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

assigning numeric(0) as units gives unitless #332

Closed edzer closed 1 year ago

edzer commented 1 year ago

I was bitten by this example:

library(units)
# udunits database from /usr/share/xml/udunits/udunits2.xml
a = 3
units(a) = NULL
a
# [1] 3
units(a) = NULL^2
a
# 3 [1]
NULL^2
# numeric(0)
units:::as_units(numeric(0))
# [1]
Enchufa2 commented 1 year ago

Note that the last result is ok. The first argument to as_units.default is the value, and the second argument is the unit (unitless by default), so this is the expected output: a unitless empty vector.