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

Formatting issue with print_md() applied to compare_parameters() #979

Merged
merged 8 commits into from
Jun 10, 2024
Merged
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
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 Expand Up @@ -207,7 +205,7 @@
#' @inheritParams model_parameters.principal
#' @rdname display.parameters_model
#' @export
display.parameters_efa <- function(object, format = "markdown", digits = 2, sort = FALSE, threshold = NULL, labels = NULL, ...) {

Check warning on line 208 in R/display.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/display.R,line=208,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 129 characters.
print_md(x = object, digits = digits, sort = sort, threshold = threshold, labels = labels, ...)
}

Expand Down
5 changes: 3 additions & 2 deletions R/format.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# usual models ---------------------------------

#' @inheritParams print.parameters_model
#' @rdname display.parameters_model
#' @rdname print.parameters_model
#' @export
format.parameters_model <- function(x,

Check warning on line 6 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=6,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 71 to at most 40.
pretty_names = TRUE,
split_components = TRUE,
select = NULL,
Expand Down Expand Up @@ -240,9 +240,10 @@
# Compare parameters ----------------------


#' @rdname print.compare_parameters
#' @inheritParams print.parameters_model
#' @export
format.compare_parameters <- function(x,

Check warning on line 246 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=246,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 43 to at most 40.
split_components = TRUE,
select = NULL,
digits = 2,
Expand Down Expand Up @@ -671,7 +672,7 @@
# 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 Expand Up @@ -808,7 +809,7 @@


# footer: type of uncertainty interval
.print_footer_cimethod <- function(x) {

Check warning on line 812 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=812,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 45 to at most 40.
if (isTRUE(getOption("parameters_cimethod", TRUE))) {
# get attributes
ci_method <- .additional_arguments(x, "ci_method", NULL)
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 Expand Up @@ -133,7 +133,7 @@
#' magnitude. In other words, the eigenvalues explain the variance of the
#' data along the new feature axes.
#'
#' @examplesIf require("nFactors", quietly = TRUE) && require("sparsepca", quietly = TRUE) && require("psych", quietly = TRUE)

Check warning on line 136 in R/principal_components.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/principal_components.R,line=136,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 126 characters.
#' library(parameters)
#'
#' \donttest{
Expand Down Expand Up @@ -280,7 +280,7 @@
# Catch and compute Rotated PCA
if (rotation != "none") {
if (sparse) {
insight::format_error("Sparse PCA is currently incompatible with rotation. Use either `sparse=TRUE` or `rotation`.")

Check warning on line 283 in R/principal_components.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/principal_components.R,line=283,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 122 characters.
}

pca_loadings <- .pca_rotate(
Expand Down Expand Up @@ -455,7 +455,7 @@
original_data = NULL,
...) {
if (!(rotation %in% c("varimax", "quartimax", "promax", "oblimin", "simplimax", "cluster", "none"))) {
insight::format_error("`rotation` must be one of \"varimax\", \"quartimax\", \"promax\", \"oblimin\", \"simplimax\", \"cluster\" or \"none\".")

Check warning on line 458 in R/principal_components.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/principal_components.R,line=458,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 147 characters.
}

if (!inherits(x, c("prcomp", "data.frame"))) {
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 @@
# compare parameters -------------------------


#' @rdname print.compare_parameters
#' @export
print_md.compare_parameters <- function(x,
digits = 2,
Expand Down Expand Up @@ -251,9 +252,9 @@
table_caption <- "(Explained) Variance of Components"

if ("Parameter" %in% names(x)) {
x$Parameter <- c("Eigenvalues", "Variance Explained", "Variance Explained (Cumulative)", "Variance Explained (Proportion)")

Check warning on line 255 in R/print_md.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/print_md.R,line=255,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
} else if ("Component" %in% names(x)) {
names(x) <- c("Component", "Eigenvalues", "Variance Explained", "Variance Explained (Cumulative)", "Variance Explained (Proportion)")

Check warning on line 257 in R/print_md.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/print_md.R,line=257,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 137 characters.
}
insight::export_table(x, digits = digits, format = "markdown", caption = table_caption, align = "firstleft")
}
Expand Down Expand Up @@ -326,7 +327,7 @@
}

if (!is.null(rope)) {
names(formatted_table)[names(formatted_table) == "% in ROPE"] <- sprintf("%% in ROPE (%.*f, %.*f)", digits, rope[1], digits, rope[2])

Check warning on line 330 in R/print_md.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/print_md.R,line=330,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 137 characters.
}

insight::export_table(formatted_table, format = "markdown", caption = table_caption, align = "firstleft")
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
Loading