r-quantities / units

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

Mixed units can't be empty #248

Closed lionel- closed 3 years ago

lionel- commented 4 years ago

I see with the dev version:

m = c(set_units(1, m), set_units(2, g), allow_mixed = TRUE)
m[0]
#> Mixed units: Error in names(dn) <- dnn : attempt to set an attribute on NULL
lionel- commented 4 years ago

They also have trouble with missing indices which are important for tidyverse support:

# Logical NA should recycle to full length
m[NA]
#> Mixed units: Error in UseMethod("units") :
#>   no applicable method for 'units' applied to an object of class "NULL"

# Integer NA should represent one missing element
m[c(NA, 1)]
#> Mixed units: Error in UseMethod("units") :
#>   no applicable method for 'units' applied to an object of class "NULL"

This would require a value representing a missing unit vector (in list classes we generally use NULL for this).