Skip to content

Commit

Permalink
refactor: remove unnecessary test_true
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muecke committed Apr 24, 2024
1 parent 7bde3de commit bd316f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/LearnerClustDiana.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LearnerClustDiana = R6Class("LearnerClustDiana",
},

.predict = function(task) {
if (test_true(self$param_set$values$k > task$nrow)) {
if (self$param_set$values$k > task$nrow) {
stopf("`k` needs to be between 1 and %s", task$nrow)
}

Expand Down
9 changes: 3 additions & 6 deletions R/LearnerClustPAM.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,13 @@ LearnerClustPAM = R6Class("LearnerClustPAM",
private = list(
.train = function(task) {
if (!is.null(self$param_set$values$medoids)) {
if (test_true(length(self$param_set$values$medoids) != self$param_set$values$k)) {
if (length(self$param_set$values$medoids) != self$param_set$values$k) {
stopf("number of `medoids`' needs to match `k`!")
}
r = map_lgl(self$param_set$values$medoids, function(i) {
test_true(i <= task$nrow) && test_true(i >= 1L)
})
r = map_lgl(self$param_set$values$medoids, function(i) i <= task$nrow && i >= 1L)
if (sum(r) != self$param_set$values$k) {
msg = sprintf("`medoids` need to contain valid indices from 1")
msg = sprintf("%s to %s (number of observations)!", msg, self$param_set$values$k)
stopf(msg)
stopf("%s to %s (number of observations)!", msg, self$param_set$values$k)
}
}

Expand Down

0 comments on commit bd316f4

Please sign in to comment.