File: ptype.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 (35 lines) | stat: -rw-r--r-- 821 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
#' Extract a prototype
#'
#' @description
#'
#' `extract_ptype()` extracts a tibble with 0 rows from `data`. This contains
#' all of the required information about column names, classes, and factor
#' levels that are required to check the structure of new data at prediction
#' time.
#'
#' @param data A data frame or matrix.
#'
#' @return
#'
#' A 0 row slice of `data` after converting it to a tibble.
#'
#' @details
#'
#' `extract_ptype()` is useful when creating a new preprocessing `blueprint`. It
#' extracts the required information that will be used by the validation checks
#' at prediction time.
#'
#' @examples
#'
#' hardhat:::extract_ptype(iris)
#' @keywords internal
#'
extract_ptype <- function(data) {
  if (is.null(data)) {
    return(NULL)
  }

  data <- check_is_data_like(data)

  vec_slice(data, 0L)
}