Skip to content

Commit f8f6701

Browse files
committed
bayesian: Simplify and expose the family call
1 parent 63f3cbd commit f8f6701

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ importFrom(rlang,call2)
2121
importFrom(rlang,enquo)
2222
importFrom(rlang,eval_tidy)
2323
importFrom(rlang,expr)
24+
importFrom(rlang,fn_fmls_names)
2425
importFrom(stats,sd)
2526
importFrom(stats,update)
2627
importFrom(tibble,as_tibble)

R/bayesian.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,25 @@ bayesian_fit <- function(formula, data, ...) {
347347
}
348348
dots$formula.override <- NULL
349349

350+
# Simplify and expose the family call
351+
if (inherits(dots$family, c("family", "brmsfamily"))) {
352+
family_chr <- purrr::map_lgl(dots$family, is.character)
353+
family_func <- ifelse(
354+
inherits(dots$family, "brmsfamily"),
355+
"brmsfamily",
356+
dots$family$family
357+
)
358+
family_fmls <- rlang::fn_fmls_names(
359+
get(
360+
family_func,
361+
mode = "function"
362+
)
363+
)
364+
family_chrs <- intersect(names(family_chr[family_chr]), family_fmls)
365+
family_args <- dots$family[family_chrs]
366+
dots$family <- rlang::call2(family_func, !!!family_args)
367+
}
368+
350369
# Pass extra arguments to Stan
351370
dots <- append(dots, dots$stan_args)
352371
dots$stan_args <- NULL

R/bayesian_init.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#' @import parsnip
33
#' @importFrom dplyr bind_cols
44
#' @importFrom purrr map_lgl
5-
#' @importFrom rlang !!! abort call2 enquo eval_tidy expr
5+
#' @importFrom rlang !!! abort call2 enquo eval_tidy expr fn_fmls_names
66
#' @importFrom stats sd update
77
#' @importFrom tibble as_tibble tibble
88
#' @importFrom utils globalVariables getFromNamespace

0 commit comments

Comments
 (0)