Skip to content

Commit

Permalink
Method extract_eq.workflow() added
Browse files Browse the repository at this point in the history
  • Loading branch information
phgrosjean committed Aug 24, 2024
1 parent 205b0ac commit 50c9a2c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ S3method(extract_eq,forecast_ARIMA)
S3method(extract_eq,glmerMod)
S3method(extract_eq,lmerMod)
S3method(extract_eq,model_fit)
S3method(extract_eq,workflow)
S3method(format,equation)
S3method(knit_print,equation)
S3method(print,equation)
Expand Down
15 changes: 9 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# equatiomatic 0.3.4
* {tidymodels} compatibility: method `extract_eq()` added for **model_fit**
objects of the {parsnip} package, see
* {tidymodels} *partial* compatibility: method `extract_eq()` added for
**model_fit** objects of the {parsnip} package, and for **workflow** objects
of the {workflows} package, see
[#237](https://github.com/datalorax/equatiomatic/pull/237). Previously,
the model object had to be extracted using `parsnip::fit()` before using
`extract_eq()`. This not necessary any more, but still valid (no breaking
changes). Note that `extract_eq()` cannot handle yet **workflow** objects
from the {workflows} package, due to the particular way variables are
handled there.
`extract_eq()`. This is not necessary any more, but still valid (no breaking
changes). Note that `extract_eq()` cannot handle yet *all* {tidymodels}. For
instance, it can handle `reg_linear()`, but cannot handle
`reg_linear() |> set_engine("stan")`. There is currently no plan to support
*all* {tidymodels} models, but pull requests will be considered if you find
and solve a problematic case by yourself.

# equatiomatic 0.3.3
* Vignette 'intro-equatiomatic' renamed 'equatiomatic' to enable a "Getting
Expand Down
59 changes: 54 additions & 5 deletions R/extract_eq.R
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,53 @@ extract_eq.model_fit <-
mean_separate = NULL, return_variances = FALSE,
se_subscripts = FALSE, ...) {

if ("fit" %in% names(model)) {
fitted_model <- model$fit
if ("fit" %in% names(model)) {
fitted_model <- model$fit
extract_eq(fitted_model, intercept = intercept, greek = greek,
greek_colors = greek_colors, subscript_colors = subscript_colors,
var_colors = var_colors,
var_subscript_colors = var_subscript_colors,
raw_tex = raw_tex,
swap_var_names = swap_var_names,
swap_subscript_names = swap_subscript_names,
ital_vars = ital_vars, label = label,
index_factors = index_factors,
show_distribution = show_distribution,
wrap = wrap, terms_per_line = terms_per_line,
operator_location = operator_location,
align_env = align_env,
use_coefs = use_coefs, coef_digits = coef_digits,
fix_signs = fix_signs, font_size = font_size,
mean_separate = mean_separate,
return_variances = return_variances,
se_subscripts = se_subscripts, ...)
} else {
stop("The 'model' does not appear to be a proper **model_fit** object ",
"because it does not have a 'fit' component.")
}
}

#' @export
#' @noRd
extract_eq.workflow <-
function(model, intercept = "alpha", greek = "beta",
greek_colors = NULL, subscript_colors = NULL,
var_colors = NULL, var_subscript_colors = NULL,
raw_tex = FALSE,
swap_var_names = NULL, swap_subscript_names = NULL,
ital_vars = FALSE, label = NULL,
index_factors = FALSE, show_distribution = FALSE,
wrap = FALSE, terms_per_line = 4,
operator_location = "end", align_env = "aligned",
use_coefs = FALSE, coef_digits = 2,
fix_signs = TRUE, font_size = NULL,
mean_separate = NULL, return_variances = FALSE,
se_subscripts = FALSE, ...) {

if ("fit" %in% names(model)) {
fitted_stage <- model$fit
if ("fit" %in% names(fitted_stage)) {
fitted_model <- fitted_stage$fit
extract_eq(fitted_model, intercept = intercept, greek = greek,
greek_colors = greek_colors, subscript_colors = subscript_colors,
var_colors = var_colors,
Expand All @@ -640,9 +685,13 @@ extract_eq.model_fit <-
fix_signs = fix_signs, font_size = font_size,
mean_separate = mean_separate,
return_variances = return_variances,
se_subscripts = se_subscripts, ...)
se_subscripts = se_subscripts, ...)
} else {
stop("The 'model' does not appear to be a proper **model_fit** object ",
"because it does not have a 'fit' component.")
stop("The 'model' does not appear to be a proper **workflow** object ",
"because it does not have a proper 'fit' component.")
}
} else {
stop("The 'model' does not appear to be a proper **workflow** object ",
"because it does not have a 'fit' component.")
}
}

0 comments on commit 50c9a2c

Please sign in to comment.