Skip to content

Commit

Permalink
Formatting issue with print_md() applied to compare_parameters() (#979)
Browse files Browse the repository at this point in the history
* Formatting issue with print_md() applied to compare_parameters()
Fixes easystats/insight#887

* docs

* docs

* docs

* dont use remotes

* lintr, docs

* docs

* fix
  • Loading branch information
strengejacke authored Jun 10, 2024
1 parent 552384e commit 5adbe97
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 138 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,3 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight, easystats/datawizard, easystats/performance, easystats/bayestestR, easystats/effectsize
14 changes: 6 additions & 8 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
#' @name display.parameters_model
#'
#' @description Prints tables (i.e. data frame) in different output formats.
#' `print_md()` is a alias for `display(format = "markdown")`, `print_html()`
#' is a alias for `display(format = "html")`. `print_table()` is for specific
#' `print_md()` is an alias for `display(format = "markdown")`, `print_html()`
#' is an alias for `display(format = "html")`. `print_table()` is for specific
#' use cases only, and currently only works for `compare_parameters()` objects.
#'
#' @param x An object returned by [`model_parameters()`][model_parameters].
#' @param object An object returned by [`model_parameters()`][model_parameters],
#' [`simulate_parameters()`][simulate_parameters],
#' [`equivalence_test()`][equivalence_test.lm] or
#' [`principal_components()`][principal_components].
#' @param x An object returned by [`model_parameters()`].
#' @param object An object returned by [`model_parameters()`],[`simulate_parameters()`],
#' [`equivalence_test()`] or [`principal_components()`].
#' @param format String, indicating the output format. Can be `"markdown"`
#' or `"html"`.
#' @param align Only applies to HTML tables. May be one of `"left"`,
Expand Down Expand Up @@ -56,7 +54,7 @@
#' effects in the table. See 'Examples'. An alternative is to set `engine = "tt"`
#' in `print_html()` to use the _tinytable_ package for creating HTML tables.
#'
#' @seealso [print.parameters_model()]
#' @seealso [print.parameters_model()] and [print.compare_parameters()]
#'
#' @examplesIf require("gt", quietly = TRUE)
#' model <- lm(mpg ~ wt + cyl, data = mtcars)
Expand Down
5 changes: 3 additions & 2 deletions R/format.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# usual models ---------------------------------

#' @inheritParams print.parameters_model
#' @rdname display.parameters_model
#' @rdname print.parameters_model
#' @export
format.parameters_model <- function(x,
pretty_names = TRUE,
Expand Down Expand Up @@ -240,6 +240,7 @@ format.parameters_brms_meta <- format.parameters_model
# Compare parameters ----------------------


#' @rdname print.compare_parameters
#' @inheritParams print.parameters_model
#' @export
format.compare_parameters <- function(x,
Expand Down Expand Up @@ -671,7 +672,7 @@ format.parameters_sem <- function(x,
# footer: r-squared
.add_footer_r2 <- function(footer = NULL, digits = 3, r2 = NULL, type = "text") {
if (!is.null(r2)) {
rsq <- .safe(paste0(unlist(lapply(r2, function(i) {
rsq <- .safe(paste(unlist(lapply(r2, function(i) {
paste0(attributes(i)$names, ": ", insight::format_value(i, digits = digits))
})), collapse = "; "))

Expand Down
2 changes: 1 addition & 1 deletion R/principal_components.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#' @param digits Argument for `print()`, indicates the number of digits
#' (rounding) to be used.
#' @param labels Argument for `print()`, character vector of same length as
#' columns in `x`. If provided, adds an additonal column with the labels.
#' columns in `x`. If provided, adds an additional column with the labels.
#' @param verbose Toggle warnings.
#' @inheritParams n_factors
#'
Expand Down
32 changes: 32 additions & 0 deletions R/print.compare_parameters.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#' @title Print comparisons of model parameters
#' @name print.compare_parameters
#'
#' @description A `print()`-method for objects from [`compare_parameters()`].
#'
#' @param x An object returned by [`compare_parameters()`].
#' @param engine Character string, naming the package or engine to be used for
#' printing into HTML or markdown format. Currently supported `"gt"` (or
#' `"default"`) to use the *gt* package to print to HTML and the default easystats
#' engine to create markdown tables. If `engine = "tt"`, the *tinytable* package
#' is used for printing to HTML or markdown. Not all `print()` methods support
#' the `"tt"` engine yet. If a specific `print()` method has no `engine` argument,
#' `insight::export_table()` is used, which uses *gt* for HTML printing.
#' @inheritParams print.parameters_model
#' @inheritSection print.parameters_model Global Options to Customize Messages and Tables when Printing
#'
#' @return Invisibly returns the original input object.
#'
#' @examplesIf require("gt", quietly = TRUE)
#' \donttest{
#' data(iris)
#' lm1 <- lm(Sepal.Length ~ Species, data = iris)
#' lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
#'
#' # custom style
#' result <- compare_parameters(lm1, lm2, select = "{estimate}{stars} ({se})")
#' print(result)
#'
#' # custom style, in HTML
#' result <- compare_parameters(lm1, lm2, select = "{estimate}<br>({se})|{p}")
#' print_html(result)
#' }
#' @export
print.compare_parameters <- function(x,
split_components = TRUE,
Expand Down
7 changes: 3 additions & 4 deletions R/print.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#' so this is just for completeness.
#' @inheritParams insight::format_table
#' @inheritParams compare_parameters
#' @inheritParams display.parameters_model
#'
#' @inheritSection format_parameters Interpretation of Interaction Terms
#' @inheritSection model_parameters Labeling the Degrees of Freedom
Expand Down Expand Up @@ -142,13 +143,11 @@
#' create HTML tables. If set to `tt`, the _tinytable_ package is used.
#'
#' @details `summary()` is a convenient shortcut for
#' `print(object, select = "minimal", show_sigma = TRUE, show_formula = TRUE)`.
#' `print(object, select = "minimal", show_sigma = TRUE, show_formula = TRUE)`.
#'
#' @return Invisibly returns the original input object.
#'
#' @seealso There is a dedicated method to use inside rmarkdown files,
#' [`print_md()`][print_md.parameters_model]. See also
#' [`display()`][display.parameters_model].
#' @seealso See also [`display()`][display.parameters_model].
#'
#' @examplesIf require("gt", quietly = TRUE) && require("glmmTMB", quietly = TRUE)
#' \donttest{
Expand Down
3 changes: 2 additions & 1 deletion R/print_html.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# normal print ----------------------------

#' @rdname display.parameters_model
#' @rdname print.parameters_model
#' @export
print_html.parameters_model <- function(x,
pretty_names = TRUE,
Expand Down Expand Up @@ -138,6 +138,7 @@ print_html.parameters_simulate <- print_html.parameters_model
#' @export
print_html.parameters_sem <- print_html.parameters_model

#' @rdname print.compare_parameters
#' @export
print_html.compare_parameters <- function(x,
caption = NULL,
Expand Down
3 changes: 2 additions & 1 deletion R/print_md.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# normal print ----------------------------

#' @rdname display.parameters_model
#' @rdname print.parameters_model
#' @export
print_md.parameters_model <- function(x,
pretty_names = TRUE,
Expand Down Expand Up @@ -123,6 +123,7 @@ print_md.parameters_simulate <- print_md.parameters_model
# compare parameters -------------------------


#' @rdname print.compare_parameters
#' @export
print_md.compare_parameters <- function(x,
digits = 2,
Expand Down
99 changes: 6 additions & 93 deletions man/display.parameters_model.Rd

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

2 changes: 1 addition & 1 deletion man/principal_components.Rd

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

Loading

0 comments on commit 5adbe97

Please sign in to comment.