Skip to content

Commit

Permalink
Use tinytable for print_md.compare_parameters()
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 13, 2024
1 parent 66dc88b commit 160833a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.21.5.6
Version: 0.21.5.7
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 2 additions & 1 deletion R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ format.compare_parameters <- function(x,
zap_small = FALSE,
format = NULL,
groups = NULL,
engine = NULL,
...) {
m_class <- attributes(x)$model_class
x$Method <- NULL
Expand Down Expand Up @@ -393,7 +394,7 @@ format.compare_parameters <- function(x,
# group parameters - this function find those parameters that should be
# grouped, reorders parameters into groups and indents lines that belong
# to one group, adding a header for each group
if (!is.null(groups)) {
if (!is.null(groups) && !identical(engine, "tt")) {
out <- .parameter_groups(out, groups)
}
indent_groups <- attributes(x)$indent_groups
Expand Down
28 changes: 20 additions & 8 deletions R/print_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ print_md.compare_parameters <- function(x,
ci_brackets = c("(", ")"),
zap_small = FALSE,
groups = NULL,
engine = "tt",
...) {
# check if user supplied digits attributes
if (missing(digits)) {
Expand All @@ -153,6 +154,9 @@ print_md.compare_parameters <- function(x,
select <- attributes(x)$output_style
}

# markdown engine?
engine <- match.arg(engine, c("tt", "default"))

Check warning on line 158 in R/print_md.R

View check run for this annotation

Codecov / codecov/patch

R/print_md.R#L158

Added line #L158 was not covered by tests

formatted_table <- format(
x,
select = select,
Expand All @@ -164,16 +168,24 @@ print_md.compare_parameters <- function(x,
ci_brackets = ci_brackets,
format = "markdown",
zap_small = zap_small,
groups = groups
groups = groups,
engine = engine

Check warning on line 172 in R/print_md.R

View check run for this annotation

Codecov / codecov/patch

R/print_md.R#L171-L172

Added lines #L171 - L172 were not covered by tests
)

insight::export_table(
formatted_table,
format = "markdown",
caption = caption,
subtitle = subtitle,
footer = footer
)
if (identical(engine, "tt")) {
insight::check_if_installed("tinytable", minimum_version = "0.1.0")
gsub("(.*) \\((.*)\\)$", "\\2", colnames(out))
gsub("(.*) \\((.*)\\)$", "\\1", colnames(out))
lapply(groups, function(i) match(i, out$Parameter))

Check warning on line 179 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=179,col=20,[unnecessary_lambda_linter] Pass match directly as a symbol to lapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)).

Check warning on line 179 in R/print_md.R

View check run for this annotation

Codecov / codecov/patch

R/print_md.R#L175-L179

Added lines #L175 - L179 were not covered by tests
} else {
insight::export_table(
formatted_table,
format = "markdown",
caption = caption,
subtitle = subtitle,
footer = footer

Check warning on line 186 in R/print_md.R

View check run for this annotation

Codecov / codecov/patch

R/print_md.R#L181-L186

Added lines #L181 - L186 were not covered by tests
)
}
}


Expand Down

0 comments on commit 160833a

Please sign in to comment.