vetiver_type_convert: Convert new data at prediction time using input data...

Description Usage Arguments Value Examples

View source: R/handlers.R

Description

This is a developer-facing function, useful for supporting new model types. At prediction time, new observations typically must be checked and sometimes converted to the data types from training time.

Usage

1
vetiver_type_convert(new_data, ptype)

Arguments

new_data

New data for making predictions, such as a data frame.

ptype

An input data prototype, such as a 0-row slice of the training data

Value

A converted dataframe

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(tibble)
training_df <- tibble(x = as.Date("2021-01-01") + 0:9,
                      y = LETTERS[1:10], z = letters[11:20])
training_df

ptype <- vctrs::vec_slice(training_df, 0)
vetiver_type_convert(tibble(x = "2021-02-01", y = "J", z = "k"), ptype)

## unsuccessful conversion generates an error:
try(vetiver_type_convert(tibble(x = "potato", y = "J", z = "k"), ptype))

tidymodels/vetiver documentation built on Jan. 14, 2022, 7:32 p.m.