Skip to content

Commit 6d002ab

Browse files
committed
perf: use %chin% and fifelse
1 parent b8bb483 commit 6d002ab

29 files changed

+61
-59
lines changed

R/PredictionClust.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ PredictionClust = R6Class("PredictionClust",
7070
#' @export
7171
as.data.table.PredictionClust = function(x, ...) { # nolint
7272
tab = as.data.table(x$data[c("row_ids", "partition")])
73-
if ("prob" %in% x$predict_types) {
73+
if ("prob" %chin% x$predict_types) {
7474
prob = as.data.table(x$data$prob)
7575
setnames(prob, new = paste0("prob.", names(prob)))
7676
tab = rcbind(tab, prob)

R/PredictionDataClust.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ create_empty_prediction_data.TaskClust = function(task, learner) {
9999
partition = integer()
100100
)
101101

102-
if ("prob" %in% predict_types) {
102+
if ("prob" %chin% predict_types) {
103103
pdata$prob = matrix(integer())
104104
}
105105

R/zzz.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ mlr3cluster_tasks = new.env()
1414
mlr3cluster_learners = new.env()
1515

1616
register_task = function(name, constructor) {
17-
if (name %in% names(mlr3cluster_tasks)) stopf("task %s registered twice", name)
17+
if (name %chin% names(mlr3cluster_tasks)) stopf("task %s registered twice", name)
1818
mlr3cluster_tasks[[name]] = constructor
1919
}
2020

2121
register_learner = function(name, constructor) {
22-
if (name %in% names(mlr3cluster_learners)) stopf("learner %s registered twice", name)
22+
if (name %chin% names(mlr3cluster_learners)) stopf("learner %s registered twice", name)
2323
mlr3cluster_learners[[name]] = constructor
2424
}
2525

README.Rmd

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ knitr::opts_chunk$set(
1212
out.width = "100%"
1313
)
1414
15+
library(data.table)
1516
library(mlr3cluster)
1617
library(mlr3misc)
1718
lrn_clust = as.data.table(mlr3::mlr_learners)[task_type == "clust", .(key, label, packages)]
@@ -64,8 +65,9 @@ Also, the package is integrated with **[mlr3viz](https://github.com/mlr-org/mlr3
6465

6566
```{r, echo = FALSE}
6667
cran_pkg = function(pkgs) {
67-
pkgs = ifelse(
68-
pkgs %in% c("stats", "graphics", "datasets"), pkgs, sprintf("[%1$s](https://cran.r-project.org/package=%1$s)", pkgs)
68+
pkgs = fifelse(
69+
pkgs %chin% c("stats", "graphics", "datasets"),
70+
pkgs, sprintf("[%1$s](https://cran.r-project.org/package=%1$s)", pkgs)
6971
)
7072
toString(pkgs)
7173
}

tests/testthat/helper_expectations.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ expect_prediction_clust = function(p) {
88
any.missing = FALSE, len = length(p$row_ids),
99
null.ok = TRUE
1010
)
11-
if ("prob" %in% p$predict_types) {
11+
if ("prob" %chin% p$predict_types) {
1212
expect_matrix(p$prob, "numeric", any.missing = FALSE, nrows = length(p$row_ids))
1313
}
1414
}

tests/testthat/test_mlr_learners_clust_agnes.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ test_that("Learner properties are respected", {
2929
p = suppressWarnings(learner$train(task)$predict(task))
3030
expect_prediction_clust(p)
3131

32-
if ("complete" %in% learner$properties) {
32+
if ("complete" %chin% learner$properties) {
3333
expect_prediction_complete(p, learner$predict_type)
3434
}
35-
if ("exclusive" %in% learner$properties) {
35+
if ("exclusive" %chin% learner$properties) {
3636
expect_prediction_exclusive(p, learner$predict_type)
3737
}
3838
}

tests/testthat/test_mlr_learners_clust_ap.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = suppressWarnings(learner$train(task)$predict(task))
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_bico.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_birch.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test_that("Learner properties are respected", {
2626
p = learner$train(task)$predict(task)
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
3535
}

tests/testthat/test_mlr_learners_clust_cmeans.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ test_that("Learner properties are respected", {
3333
p = learner$train(task)$predict(task)
3434
expect_prediction_clust(p)
3535

36-
if ("complete" %in% learner$properties) {
36+
if ("complete" %chin% learner$properties) {
3737
expect_prediction_complete(p, learner$predict_type)
3838
}
39-
if ("exclusive" %in% learner$properties) {
39+
if ("exclusive" %chin% learner$properties) {
4040
expect_prediction_exclusive(p, learner$predict_type)
4141
}
42-
if ("fuzzy" %in% learner$properties) {
42+
if ("fuzzy" %chin% learner$properties) {
4343
expect_prediction_fuzzy(p)
4444
}
4545
}

tests/testthat/test_mlr_learners_clust_cobweb.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_dbscan.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test_that("Learner properties are respected", {
2626
p = learner$train(task)$predict(task)
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
3535
}

tests/testthat/test_mlr_learners_clust_dbscan_fpc.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test_that("Learner properties are respected", {
2626
p = learner$train(task)$predict(task)
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
3535
}

tests/testthat/test_mlr_learners_clust_diana.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ test_that("Learner properties are respected", {
2929
p = suppressWarnings(learner$train(task)$predict(task))
3030
expect_prediction_clust(p)
3131

32-
if ("complete" %in% learner$properties) {
32+
if ("complete" %chin% learner$properties) {
3333
expect_prediction_complete(p, learner$predict_type)
3434
}
35-
if ("exclusive" %in% learner$properties) {
35+
if ("exclusive" %chin% learner$properties) {
3636
expect_prediction_exclusive(p, learner$predict_type)
3737
}
3838
}

tests/testthat/test_mlr_learners_clust_em.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_fanny.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ test_that("Learner properties are respected", {
2828
p = suppressWarnings(learner$train(task)$predict(task))
2929
expect_prediction_clust(p)
3030

31-
if ("complete" %in% learner$properties) {
31+
if ("complete" %chin% learner$properties) {
3232
expect_prediction_complete(p, learner$predict_type)
3333
}
34-
if ("exclusive" %in% learner$properties) {
34+
if ("exclusive" %chin% learner$properties) {
3535
expect_prediction_exclusive(p, learner$predict_type)
3636
}
37-
if ("fuzzy" %in% learner$properties) {
37+
if ("fuzzy" %chin% learner$properties) {
3838
expect_prediction_fuzzy(p)
3939
}
4040
}

tests/testthat/test_mlr_learners_clust_featureless.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ test_that("Learner properties are respected", {
2424
p = learner$train(task)$predict(task)
2525
expect_prediction_clust(p)
2626

27-
if ("complete" %in% learner$properties) {
27+
if ("complete" %chin% learner$properties) {
2828
expect_prediction_complete(p, learner$predict_type)
2929
}
30-
if ("exclusive" %in% learner$properties) {
30+
if ("exclusive" %chin% learner$properties) {
3131
expect_prediction_exclusive(p, learner$predict_type)
3232
}
3333
}

tests/testthat/test_mlr_learners_clust_ff.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_hclust.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ test_that("Learner properties are respected", {
2626
p = suppressWarnings(learner$train(task)$predict(task))
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
35-
if ("fuzzy" %in% learner$properties) {
35+
if ("fuzzy" %chin% learner$properties) {
3636
expect_prediction_fuzzy(p)
3737
}
3838
}

tests/testthat/test_mlr_learners_clust_hdbscan.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_kkmeans.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ test_that("Learner properties are respected", {
3333
p = learner$train(task)$predict(task)
3434
expect_prediction_clust(p)
3535

36-
if ("complete" %in% learner$properties) {
36+
if ("complete" %chin% learner$properties) {
3737
expect_prediction_complete(p, learner$predict_type)
3838
}
39-
if ("exclusive" %in% learner$properties) {
39+
if ("exclusive" %chin% learner$properties) {
4040
expect_prediction_exclusive(p, learner$predict_type)
4141
}
4242

tests/testthat/test_mlr_learners_clust_kmeans.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ test_that("Learner properties are respected", {
3333
p = learner$train(task)$predict(task)
3434
expect_prediction_clust(p)
3535

36-
if ("complete" %in% learner$properties) {
36+
if ("complete" %chin% learner$properties) {
3737
expect_prediction_complete(p, learner$predict_type)
3838
}
39-
if ("exclusive" %in% learner$properties) {
39+
if ("exclusive" %chin% learner$properties) {
4040
expect_prediction_exclusive(p, learner$predict_type)
4141
}
4242

tests/testthat/test_mlr_learners_clust_mbatchkmeans.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ test_that("Learner properties are respected", {
3838
p = learner$train(task)$predict(task)
3939
expect_prediction_clust(p)
4040

41-
if ("complete" %in% learner$properties) {
41+
if ("complete" %chin% learner$properties) {
4242
expect_prediction_complete(p, learner$predict_type)
4343
}
44-
if ("exclusive" %in% learner$properties) {
44+
if ("exclusive" %chin% learner$properties) {
4545
expect_prediction_exclusive(p, "partition")
4646
}
4747
if (learner$predict_type == "prob") {

tests/testthat/test_mlr_learners_clust_mclust.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ test_that("Learner properties are respected", {
2626
p = suppressWarnings(learner$train(task)$predict(task))
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
35-
if ("fuzzy" %in% learner$properties) {
35+
if ("fuzzy" %chin% learner$properties) {
3636
expect_prediction_fuzzy(p)
3737
}
3838
}

tests/testthat/test_mlr_learners_clust_meanshift.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ test_that("Learner properties are respected", {
2828
p = suppressWarnings(learner$train(task)$predict(task))
2929
expect_prediction_clust(p)
3030

31-
if ("complete" %in% learner$properties) {
31+
if ("complete" %chin% learner$properties) {
3232
expect_prediction_complete(p, learner$predict_type)
3333
}
34-
if ("exclusive" %in% learner$properties) {
34+
if ("exclusive" %chin% learner$properties) {
3535
expect_prediction_exclusive(p, learner$predict_type)
3636
}
3737
}

tests/testthat/test_mlr_learners_clust_optics.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test_that("Learner properties are respected", {
2626
p = learner$train(task)$predict(task)
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
3535
}

tests/testthat/test_mlr_learners_clust_pam.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test_that("Learner properties are respected", {
2626
p = learner$train(task)$predict(task)
2727
expect_prediction_clust(p)
2828

29-
if ("complete" %in% learner$properties) {
29+
if ("complete" %chin% learner$properties) {
3030
expect_prediction_complete(p, learner$predict_type)
3131
}
32-
if ("exclusive" %in% learner$properties) {
32+
if ("exclusive" %chin% learner$properties) {
3333
expect_prediction_exclusive(p, learner$predict_type)
3434
}
3535
}

tests/testthat/test_mlr_learners_clust_simplekmeans.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

tests/testthat/test_mlr_learners_clust_xmeans.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test_that("Learner properties are respected", {
2727
p = learner$train(task)$predict(task)
2828
expect_prediction_clust(p)
2929

30-
if ("complete" %in% learner$properties) {
30+
if ("complete" %chin% learner$properties) {
3131
expect_prediction_complete(p, learner$predict_type)
3232
}
33-
if ("exclusive" %in% learner$properties) {
33+
if ("exclusive" %chin% learner$properties) {
3434
expect_prediction_exclusive(p, learner$predict_type)
3535
}
3636
}

0 commit comments

Comments
 (0)