From kmbe||56 @end|ng |rom gm@||@com  Mon Jan 21 01:39:45 2019
From: kmbe||56 @end|ng |rom gm@||@com (Kenny Bell)
Date: Mon, 21 Jan 2019 13:39:45 +1300
Subject: [Rd] Request: make `var` a generic
Message-ID: <CAPekMCnOKB4A7utzh1ocEYJnhBWY0=YrXiXmp5X47c9Avgc0TA@mail.gmail.com>

Hi all,

I am running into problems using `summary.lm` as calling `var` on a `units`
object does not retain the `units` attribute.

The units package addresses this issue for `mean` by implementing
`mean.units`:

units:::mean.units
function (x, ...)
{
    .as.units(NextMethod(), units(x))
}

This is, however, not possible for `var` (as it's not a generic), which
breaks `summary.lm`:

```
library(units)
#> udunits system database from C:/R/Library/3.5/units/share/udunits
iris$Sepal.Length <- set_units(iris$Sepal.Length, "cm")

summary(lm(Sepal.Length ~ Sepal.Width,
           data = iris))
#> Error in Ops.units(mean(f)^2, var(f)): both operands of the expression
should be "units" objects
```

Created on 2019-01-21 by the [reprex package](https://reprex.tidyverse.org)
(v0.2.1.9000)

Apologies if `stats` package emails shouldn't go here.

Cheers,
Kenny

	[[alternative HTML version deleted]]



[Rd] Request: make `var` a generic
Kenny Bell