File: helper.R

package info (click to toggle)
r-cran-recipes 1.0.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,636 kB
  • sloc: sh: 37; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
# This step is created solely for testing purposes
step_testthat_helper <-
  function(recipe,
           ...,
           output = NULL,
           role = "predictor",
           trained = FALSE,
           skip = FALSE,
           id = rand_id("testthat_helper")) {
    add_step(
      recipe,
      step_testthat_helper_new(
        terms = enquos(...),
        output = output,
        role = role,
        trained = trained,
        skip = skip,
        id = id
      )
    )
  }

step_testthat_helper_new <-
  function(terms, output, role, trained, skip, id) {
    step(
      subclass = "testthat_helper",
      terms = terms,
      output = output,
      role = role,
      trained = trained,
      skip = skip,
      id = id
    )
  }

#' @export
prep.step_testthat_helper <- function(x, training, info = NULL, ...) {
  step_testthat_helper_new(
    terms = x$terms,
    output = x$output,
    role = x$role,
    trained = TRUE,
    skip = x$skip,
    id = x$id
  )
}

#' @export
bake.step_testthat_helper <- function(object, new_data, ...) {
  object$output %||% new_data
}