Skip to content

Commit

Permalink
rework #363; we really need to use NextMethod to avoid breaking quant…
Browse files Browse the repository at this point in the history
…ities
  • Loading branch information
Enchufa2 committed Jan 15, 2024
1 parent f56521c commit 928e883
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: units
Version: 0.8-5.2
Version: 0.8-5.3
Title: Measurement Units for R Vectors
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0001-8049-7069")),
person("Thomas", "Mailund", role = "aut", email = "[email protected]"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

* Performance improvements in `data.frame` methods; suggested in #361 @grcatlin

* Unclass object for summaries, instead of using `NextMethod`; #363
* Fix `weighted.mean.units` for unitless objects; #363

# version 0.8-5

Expand Down
8 changes: 6 additions & 2 deletions R/summaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ print.units = function (x, ...) { # nocov start

#' @export
mean.units = function(x, ...) {
.as.units(mean(unclass(x), ...), units(x))
.as.units(NextMethod(), units(x))
}

#' @export
weighted.mean.units = function(x, w, ...) {
.as.units(weighted.mean(unclass(x), unclass(w), ...), units(x))
u <- units(x)
x <- drop_units(x)
if (!missing(w))
w <- unclass(w)
.as.units(NextMethod(), u)
}

#' @export
Expand Down

0 comments on commit 928e883

Please sign in to comment.