Skip to content

Commit 657d613

Browse files
committed
checks on arguments
1 parent fc70659 commit 657d613

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

R/aggregate_hclust.R

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ step_aggregate_hclust_new <- function(terms, role, trained,
112112
prep.step_aggregate_hclust <- function(x, training, info = NULL, ...) {
113113
col_names <- recipes_eval_select(x$terms, training, info)
114114
check_type(training[, col_names], quant = TRUE)
115+
check_in(x$dist_metric, name_x = "dist_metric",
116+
values = c("euclidean", "maximum", "manhattan",
117+
"canberra", "binary", "minkowski"))
118+
check_in(x$linkage_method, name_x = "linkage_method",
119+
values = c("ward.D", "ward.D2", "single", "complete",
120+
"average", "mcquitty", "median", "centroid"))
115121

116122
ct <-
117123
training[, col_names] %>%

tests/testthat/test-aggregate_hclust.R

+24
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,27 @@ test_that("step_aggregate_hclust works", {
9191
expect_equal(colnames(baked2),
9292
c(colnames(cheese_abundance), new_names))
9393
})
94+
95+
96+
test_that("step_aggregate_hclust throws errors", {
97+
98+
expect_error(
99+
recipe(~ ., data = cheese_abundance) %>%
100+
step_aggregate_hclust(all_numeric_predictors(),
101+
n_clusters = nc, fun_agg = sum,
102+
dist_metric = "hello") %>%
103+
prep(),
104+
'`dist_metric` must be one of "euclidean",'
105+
)
106+
107+
expect_error(
108+
recipe(~ ., data = cheese_abundance) %>%
109+
step_aggregate_hclust(all_numeric_predictors(),
110+
n_clusters = nc, fun_agg = sum,
111+
linkage_method = "hello") %>%
112+
prep(),
113+
'`linkage_method` must be one of "ward.D",'
114+
)
115+
116+
117+
})

0 commit comments

Comments
 (0)