File: print.R

package info (click to toggle)
r-cran-hardhat 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,656 kB
  • sloc: sh: 13; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 981 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' @export
format.xy_blueprint <- function(x, ...) "XY"

#' @export
format.recipe_blueprint <- function(x, ...) "Recipe"

#' @export
format.formula_blueprint <- function(x, ...) "Formula"

#' @export
print.hardhat_blueprint <- function(x, ...) {
  cat_line("{format(x)} blueprint:")
  cat_line("\n")
  cat_line("# Predictors: {n_blueprint_predictors(x)}")
  cat_line("  # Outcomes: {n_blueprint_outcomes(x)}")
  cat_line("   Intercept: {x$intercept}")
  cat_line("Novel Levels: {x$allow_novel_levels}")
  cat_line(" Composition: {x$composition}")
  invisible(x)
}

#' @export
print.formula_blueprint <- function(x, ...) {
  NextMethod()
  cat_line("  Indicators: {x$indicators}")
  invisible(x)
}

cat_line <- function(..., .envir = parent.frame()) {
  lines <- paste(glue(..., .envir = .envir), "\n")
  cat(lines, sep = "")
}

n_blueprint_predictors <- function(x) {
  ncol(x$ptypes$predictors) %||% 0L
}

n_blueprint_outcomes <- function(x) {
  ncol(x$ptypes$outcomes) %||% 0L
}