From edzer@pebe@m@ @end|ng |rom un|-muen@ter@de  Mon Jan 21 08:11:11 2019
From: edzer@pebe@m@ @end|ng |rom un|-muen@ter@de (Edzer Pebesma)
Date: Mon, 21 Jan 2019 08:11:11 +0100
Subject: [Rd] Request: make `var` a generic
In-Reply-To: <CAPekMCnOKB4A7utzh1ocEYJnhBWY0=YrXiXmp5X47c9Avgc0TA@mail.gmail.com>
References: <CAPekMCnOKB4A7utzh1ocEYJnhBWY0=YrXiXmp5X47c9Avgc0TA@mail.gmail.com>
Message-ID: <4037bc1e-ab0e-7533-5385-8a07154e24c6@uni-muenster.de>

Hi Kenny,

yes, there's only so much you can do with S3 methods penetrating other
packages' code; I?aki discusses this in the blog about the r-quantities
project found at:

https://www.r-spatial.org/r/2018/08/31/quantities-final.html#fitting-linear-models-with-quantities

I'm not sure whether making "var" a generic would not shift the problem
to the next function not being generic, you could experiment with that.

On 1/20/19 6:39 PM, Kenny Bell wrote:
> 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]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081


[Rd] Request: make `var` a generic
Edzer Pebesma