From 71187bce521d30637993c8dbc3e0dd9a4c683a82 Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Thu, 22 Aug 2024 22:39:12 +0300 Subject: [PATCH] Update p_direction.R --- R/p_direction.R | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/R/p_direction.R b/R/p_direction.R index 477f97c26..e6bf21e98 100644 --- a/R/p_direction.R +++ b/R/p_direction.R @@ -174,8 +174,26 @@ p_direction.numeric <- function(x, method = "direct", null = 0, ...) { #' @rdname p_direction +#' @param rvar_col Name of an `rvar`-type column. If `NULL`, each column in the +#' data frame is assumed to represent draws from a posterior distribution. #' @export -p_direction.data.frame <- function(x, method = "direct", null = 0, ...) { +p_direction.data.frame <- function(x, method = "direct", null = 0, rvar_col = NULL, ...) { + if (is.null(rvar_col)) { + return(.p_direction_df(x, method = method, null = null, ...)) + } + + stopifnot(length(rvar_col) == 1L, + is.character(rvar_col), + rvar_col %in% colnames(x)) + + + out <- p_direction(x[[rvar_col]], method = method, null = null, ...) + x[["pd"]] <- out[["pd"]] + x +} + +#' @keywords internal +.p_direction_df <- function(x, method = "direct", null = 0, ...) { obj_name <- insight::safe_deparse_symbol(substitute(x)) x <- .select_nums(x)