|
1 |
| -#' Recipe blueprint that accounts for `epi_df` panel data |
2 |
| -#' |
3 |
| -#' Used for simplicity. See [hardhat::new_recipe_blueprint()] or |
4 |
| -#' [hardhat::default_recipe_blueprint()] for more details. |
5 |
| -#' |
6 |
| -#' @inheritParams hardhat::new_recipe_blueprint |
| 1 | +#' Default epi_recipe blueprint |
7 | 2 | #'
|
8 |
| -#' @details The `bake_dependent_roles` are automatically set to `epi_df` defaults. |
9 |
| -#' @return A recipe blueprint. |
| 3 | +#' Recipe blueprint that accounts for `epi_df` panel data |
| 4 | +#' Used for simplicity. See [hardhat::default_recipe_blueprint()] for more |
| 5 | +#' details. This subclass is nearly the same, except it ensures that |
| 6 | +#' downstream processing doesn't drop the epi_df class from the data. |
10 | 7 | #'
|
11 |
| -#' @keywords internal |
| 8 | +#' @inheritParams hardhat::default_recipe_blueprint |
| 9 | +#' @return A `epi_recipe` blueprint. |
12 | 10 | #' @export
|
13 |
| -new_epi_recipe_blueprint <- |
14 |
| - function(intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, |
15 |
| - composition = "tibble", |
16 |
| - ptypes = NULL, recipe = NULL, ..., subclass = character()) { |
17 |
| - hardhat::new_recipe_blueprint( |
18 |
| - intercept = intercept, |
19 |
| - allow_novel_levels = allow_novel_levels, |
20 |
| - fresh = fresh, |
21 |
| - composition = composition, |
22 |
| - ptypes = ptypes, |
23 |
| - recipe = recipe, |
24 |
| - ..., |
25 |
| - subclass = c(subclass, "epi_recipe_blueprint") |
26 |
| - ) |
27 |
| - } |
28 |
| - |
29 |
| - |
30 |
| -#' @rdname new_epi_recipe_blueprint |
31 |
| -#' @export |
32 |
| -epi_recipe_blueprint <- |
33 |
| - function(intercept = FALSE, allow_novel_levels = FALSE, |
34 |
| - fresh = TRUE, |
35 |
| - composition = "tibble") { |
36 |
| - new_epi_recipe_blueprint( |
37 |
| - intercept = intercept, |
38 |
| - allow_novel_levels = allow_novel_levels, |
39 |
| - fresh = fresh, |
40 |
| - composition = composition |
41 |
| - ) |
42 |
| - } |
| 11 | +#' @keywords internal |
| 12 | +default_epi_recipe_blueprint <- function(intercept = FALSE, |
| 13 | + allow_novel_levels = FALSE, |
| 14 | + fresh = TRUE, |
| 15 | + strings_as_factors = FALSE, |
| 16 | + composition = "tibble") { |
| 17 | + new_default_epi_recipe_blueprint( |
| 18 | + intercept = intercept, |
| 19 | + allow_novel_levels = allow_novel_levels, |
| 20 | + fresh = fresh, |
| 21 | + strings_as_factors = strings_as_factors, |
| 22 | + composition = composition |
| 23 | + ) |
| 24 | +} |
43 | 25 |
|
44 |
| -#' @rdname new_epi_recipe_blueprint |
45 |
| -#' @export |
46 |
| -default_epi_recipe_blueprint <- |
47 |
| - function(intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, |
48 |
| - composition = "tibble") { |
49 |
| - new_default_epi_recipe_blueprint( |
50 |
| - intercept = intercept, |
51 |
| - allow_novel_levels = allow_novel_levels, |
52 |
| - fresh = fresh, |
53 |
| - composition = composition |
54 |
| - ) |
55 |
| - } |
| 26 | +new_default_epi_recipe_blueprint <- function(intercept = FALSE, |
| 27 | + allow_novel_levels = TRUE, |
| 28 | + fresh = TRUE, |
| 29 | + strings_as_factors = FALSE, |
| 30 | + composition = "tibble", |
| 31 | + ptypes = NULL, |
| 32 | + recipe = NULL, |
| 33 | + extra_role_ptypes = NULL, |
| 34 | + ..., |
| 35 | + subclass = character()) { |
| 36 | + hardhat::new_recipe_blueprint( |
| 37 | + intercept = intercept, |
| 38 | + allow_novel_levels = allow_novel_levels, |
| 39 | + fresh = fresh, |
| 40 | + strings_as_factors = strings_as_factors, |
| 41 | + composition = composition, |
| 42 | + ptypes = ptypes, |
| 43 | + recipe = recipe, |
| 44 | + extra_role_ptypes = extra_role_ptypes, |
| 45 | + ..., |
| 46 | + subclass = c(subclass, "default_epi_recipe_blueprint", "default_recipe_blueprint") |
| 47 | + ) |
| 48 | +} |
56 | 49 |
|
57 |
| -#' @rdname new_epi_recipe_blueprint |
58 |
| -#' @inheritParams hardhat::new_default_recipe_blueprint |
59 |
| -#' @export |
60 |
| -new_default_epi_recipe_blueprint <- |
61 |
| - function(intercept = FALSE, allow_novel_levels = FALSE, |
62 |
| - fresh = TRUE, |
63 |
| - composition = "tibble", ptypes = NULL, recipe = NULL, |
64 |
| - extra_role_ptypes = NULL, ..., subclass = character()) { |
65 |
| - new_epi_recipe_blueprint( |
66 |
| - intercept = intercept, |
67 |
| - allow_novel_levels = allow_novel_levels, |
68 |
| - fresh = fresh, |
69 |
| - composition = composition, |
70 |
| - ptypes = ptypes, |
71 |
| - recipe = recipe, |
72 |
| - extra_role_ptypes = extra_role_ptypes, |
73 |
| - ..., |
74 |
| - subclass = c(subclass, "default_epi_recipe_blueprint", "default_recipe_blueprint") |
75 |
| - ) |
76 |
| - } |
77 | 50 |
|
78 | 51 | #' @importFrom hardhat run_mold
|
79 | 52 | #' @export
|
80 | 53 | run_mold.default_epi_recipe_blueprint <- function(blueprint, ..., data) {
|
81 | 54 | rlang::check_dots_empty0(...)
|
82 |
| - # blueprint <- hardhat:::patch_recipe_default_blueprint(blueprint) |
83 |
| - cleaned <- mold_epi_recipe_default_clean(blueprint = blueprint, data = data) |
84 |
| - blueprint <- cleaned$blueprint |
85 |
| - data <- cleaned$data |
| 55 | + # we don't do the "cleaning" in `hardhat:::run_mold.default_recipe_blueprint` |
| 56 | + # That function drops the epi_df class without any recourse. |
| 57 | + # The only way we should be here at all is if `data` is an epi_df, but just |
| 58 | + # in case... |
| 59 | + if (!is_epi_df(data)) { |
| 60 | + cli_warn("`data` is not an {.cls epi_df}. It has class {.cls {class(data)}}.") |
| 61 | + } |
86 | 62 | hardhat:::mold_recipe_default_process(blueprint = blueprint, data = data)
|
87 | 63 | }
|
88 | 64 |
|
89 |
| -mold_epi_recipe_default_clean <- function(blueprint, data) { |
90 |
| - hardhat:::check_data_frame_or_matrix(data) |
91 |
| - if (!is_epi_df(data)) data <- hardhat:::coerce_to_tibble(data) |
92 |
| - hardhat:::new_mold_clean(blueprint, data) |
93 |
| -} |
94 |
| - |
95 | 65 | #' @importFrom hardhat refresh_blueprint
|
96 | 66 | #' @export
|
97 | 67 | refresh_blueprint.default_epi_recipe_blueprint <- function(blueprint) {
|
98 | 68 | do.call(new_default_epi_recipe_blueprint, as.list(blueprint))
|
99 | 69 | }
|
100 |
| - |
101 |
| - |
102 |
| -## removing this function? |
103 |
| -# er_check_is_data_like <- function(.x, .x_nm) { |
104 |
| -# if (rlang::is_missing(.x_nm)) { |
105 |
| -# .x_nm <- rlang::as_label(rlang::enexpr(.x)) |
106 |
| -# } |
107 |
| -# if (!hardhat:::is_new_data_like(.x)) { |
108 |
| -# hardhat:::glubort("`{.x_nm}` must be a data.frame or a matrix, not a {class1(.x)}.") |
109 |
| -# } |
110 |
| -# .x |
111 |
| -# } |
0 commit comments