diff --git a/DESCRIPTION b/DESCRIPTION index f7bd15d..a566833 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "edzer.pebesma@uni-muenster.de", comment = c(ORCID = "0000-0001-8049-7069")), person("Thomas", "Mailund", role = "aut", email = "mailund@birc.au.dk"), diff --git a/NEWS.md b/NEWS.md index d69dab9..9ec692e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/summaries.R b/R/summaries.R index 8dcf332..84cd5dc 100644 --- a/R/summaries.R +++ b/R/summaries.R @@ -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