-
Notifications
You must be signed in to change notification settings - Fork 28
/
prepare.R
51 lines (48 loc) · 1.89 KB
/
prepare.R
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
#' Model constructor methods
#'
#' These are developer-facing functions, useful for supporting new model types.
#' Each model supported by [`vetiver_model()`] uses up to four methods when the
#' deployable object is created:
#' - The `vetiver_create_description()` function generates a helpful description
#' of the model based on its characteristics. This method is required.
#' - The [vetiver_create_meta()] function creates the correct [vetiver_meta()]
#' for the model. This is especially helpful for specifying which packages are
#' needed for prediction. A model can use the default method here, which is
#' to have no special metadata.
#' - The [vetiver_ptype()] function finds an input data prototype from the
#' training data (a zero-row slice) to use for checking at prediction time.
#' This method is required.
#' - The `vetiver_prepare_model()` function executes last. Use this function
#' for tasks like checking if the model is trained and reducing the size of the
#' model via [butcher::butcher()]. A model can use the default method here,
#' which is to return the model without changes.
#'
#' @inheritParams vetiver_model
#' @details These are four generics that use the class of `model` for dispatch.
#'
#' @examples
#'
#' cars_lm <- lm(mpg ~ ., data = mtcars)
#' vetiver_create_description(cars_lm)
#' vetiver_prepare_model(cars_lm)
#'
#' @rdname vetiver_create_description
#' @export
vetiver_create_description <- function(model) {
UseMethod("vetiver_create_description")
}
#' @rdname vetiver_create_description
#' @export
vetiver_create_description.default <- function(model) {
abort("There is no method available to create a description for `model`.")
}
#' @rdname vetiver_create_description
#' @export
vetiver_prepare_model <- function(model) {
UseMethod("vetiver_prepare_model")
}
#' @rdname vetiver_create_description
#' @export
vetiver_prepare_model.default <- function(model) {
model
}