From d4c53dc613fcea81a71e49c8d4da08f8ecfaf088 Mon Sep 17 00:00:00 2001 From: jrnold Date: Sat, 25 Feb 2017 22:39:48 -0800 Subject: [PATCH] Add dots to typical generic function Add dots to the typical generic function. It's not currently used by any methods, but it could be in the future. --- NEWS.md | 2 ++ R/typical.R | 11 ++++++----- man/typical.Rd | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 49a89e0..d68f0a2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # modelr 0.1.1.9000 +* Added `...` argument to the `typical()` generic function (@jrnold, #42) + # modelr 0.1.1 * Added a `NEWS.md` file to track changes to the package. diff --git a/R/typical.R b/R/typical.R index 2fa53e8..c248091 100644 --- a/R/typical.R +++ b/R/typical.R @@ -6,6 +6,7 @@ #' always silently dropped. #' #' @param x A vector +#' @param ... Arguments used by methods #' @export #' @examples #' # median of numeric vector @@ -19,28 +20,28 @@ #' # if tied, returns them all #' x <- c("a", "a", "b", "b", "c") #' typical(x) -typical <- function(x) { +typical <- function(x, ...) { UseMethod("typical") } #' @export -typical.numeric <- function(x) { +typical.numeric <- function(x, ...) { stats::median(x, na.rm = TRUE) } #' @export -typical.factor <- function(x) { +typical.factor <- function(x, ...) { counts <- table(x) levels(x)[max(counts) == counts] } #' @export -typical.character <- function(x) { +typical.character <- function(x, ...) { counts <- table(x) names(counts)[max(counts) == counts] } #' @export -typical.logical <- function(x) { +typical.logical <- function(x, ...) { mean(x, na.rm = TRUE) >= 0.5 } diff --git a/man/typical.Rd b/man/typical.Rd index 30db90d..74b5222 100644 --- a/man/typical.Rd +++ b/man/typical.Rd @@ -4,10 +4,12 @@ \alias{typical} \title{Find the typical value} \usage{ -typical(x) +typical(x, ...) } \arguments{ \item{x}{A vector} + +\item{...}{Arguments used by methods} } \description{ For numeric vectors, it returns the median. For factors, characters, and