r-quantities/units

%*% drops units without warning

Closed this issue · 1 comments

edzer commented

Example:

> f = function(a, b, c) sum(a * b) / sum(c)
> g = function(a, b, c) sum(a %*% b) / sum(c)
> library(units)
> a = set_units(1:3, m)
> b = set_units(1:3, s)
> c = set_units(1:3, m*s)
> f(a,b,c)
2.333333 1
> g(a,b,c)
2.333333 1/m/s

(see also r-quantities/errors#11)

The resolution I can see is to have

2 * set_units(2, km/h)

give a warning that 2 has no units, but is assumed to have unit 1, and explicitly require

set_units(2) * set_units(2, km/h)

to get rid of this warning. This means: to drop the implicit assumption that numbers without units have unit 1. (In the context of errors: not implicitly assume that unclassed numbers have zero error.)

Seems a good solution to me to avoid patching %*% and potentially many related functions.