Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make functions pipe-friendly #320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
S3method(describe_nonlinear,data.frame)
S3method(describe_nonlinear,estimate_predicted)
S3method(describe_nonlinear,numeric)
S3method(estimate_contrasts,default)
S3method(estimate_contrasts,estimate_means)
S3method(estimate_contrasts,estimate_slopes)
S3method(format,estimate_contrasts)
S3method(format,estimate_grouplevel)
S3method(format,estimate_means)
Expand Down
46 changes: 35 additions & 11 deletions R/estimate_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,24 @@
#'
#' @return A data frame of estimated contrasts.
#' @export
estimate_contrasts <- function(model,
contrast = NULL,
by = NULL,
predict = NULL,
ci = 0.95,
p_adjust = "holm",
comparison = "pairwise",
backend = getOption("modelbased_backend", "emmeans"),
transform = NULL,
verbose = TRUE,
...) {
estimate_contrasts <- function(model, ...) {
UseMethod("estimate_contrasts")
}


#' @export
#' @rdname estimate_contrasts
estimate_contrasts.default <- function(model,
contrast = NULL,
by = NULL,
predict = NULL,
ci = 0.95,
p_adjust = "holm",
comparison = "pairwise",
backend = getOption("modelbased_backend", "emmeans"),
transform = NULL,
verbose = TRUE,
...) {
## TODO: remove deprecation warning later
if (!is.null(transform)) {
insight::format_warning("Argument `transform` is deprecated. Please use `predict` instead.")
Expand Down Expand Up @@ -173,3 +180,20 @@ estimate_contrasts <- function(model,
class(out) <- c("estimate_contrasts", "see_estimate_contrasts", class(out))
out
}


#' @export
estimate_contrasts.estimate_means <- function(model, ...) {
x <- attributes(model)$model
contrast <- attributes(model)$by
# prepare dots - `by` must be removed
dot_args <- list(...)
dot_args$by <- NULL
# function arguments
fun_args <- c(list(x, contrast = contrast), dot_args)
# call contrasts function
do.call(estimate_contrasts, insight::compact_list(fun_args))
}

#' @export
estimate_contrasts.estimate_slopes <- estimate_contrasts.estimate_means
9 changes: 6 additions & 3 deletions man/estimate_contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading