Skip to content
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.15.2
Version: 0.15.2.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# performance (devel)

## Changes

* Improved documentation for printing-methods.

# performance 0.15.2

## Bug fixes
Expand Down
6 changes: 5 additions & 1 deletion R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#' @param layout Table layout (can be either `"horizontal"` or `"vertical"`).
#' @param digits Number of decimal places.
#' @param caption Table caption as string. If `NULL`, no table caption is printed.
#' @param ... Currently not used.
#' @param ... Arguments passed to other methods, e.g. `format()` (and thereby to
#' [`insight::format_table()`] or [`insight::export_table()`]. See related
#' documentation for details on available arguments. For example, to control
#' digits for information criteria like AIC or BIC, use `ic_digits = <value>`.
#'
#' @section Global Options to Customize Output when Printing:
#'
Expand All @@ -35,6 +38,7 @@
#' model <- lm(mpg ~ wt + cyl, data = mtcars)
#' mp <- model_performance(model)
#' display(mp)
#' display(mp, digits = 3, ic_digits = 4)
#' @export
display.performance_model <- function(
object,
Expand Down
33 changes: 0 additions & 33 deletions R/model_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,3 @@ model_performance <- function(model, ...) {
#' @rdname model_performance
#' @export
performance <- model_performance


# methods --------------------------------

#' @export
print.performance_model <- function(x, digits = 3, layout = "horizontal", ...) {
layout <- insight::validate_argument(
layout,
c("horizontal", "vertical")
)
formatted_table <- format(x = x, digits = digits, format = "text", ...)

# switch to vertical layout
if (layout == "vertical") {
formatted_table <- datawizard::rownames_as_column(
as.data.frame(t(formatted_table)),
"Metric"
)
colnames(formatted_table)[2] <- "Value"
}

cat(
insight::export_table(
x = formatted_table,
digits = digits,
format = "text",
caption = c("# Indices of model performance", "blue"),
...
)
)

invisible(x)
}
32 changes: 32 additions & 0 deletions R/print-methods.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#' @rdname display.performance_model
#' @export
print.performance_model <- function(x, digits = 3, layout = "horizontal", ...) {
layout <- insight::validate_argument(
layout,
c("horizontal", "vertical")
)
formatted_table <- format(x = x, digits = digits, format = "text", ...)

# switch to vertical layout
if (layout == "vertical") {
formatted_table <- datawizard::rownames_as_column(
as.data.frame(t(formatted_table)),
"Metric"
)
colnames(formatted_table)[2] <- "Value"
}

cat(
insight::export_table(
x = formatted_table,
digits = digits,
format = "text",
caption = c("# Indices of model performance", "blue"),
...
)
)

invisible(x)
}


#' @export
print.r2_generic <- function(x, digits = 3, ...) {
model_type <- attr(x, "model_type")
Expand Down Expand Up @@ -49,7 +81,7 @@
}

# separate lines for multiple R2
out <- paste0(out, collapse = "\n")

Check warning on line 84 in R/print-methods.R

View workflow job for this annotation

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

file=R/print-methods.R,line=84,col=10,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

cat(out)
cat("\n")
Expand Down
11 changes: 9 additions & 2 deletions man/display.performance_model.Rd

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

Loading