diff --git a/R/LearnerClustAffinityPropagation.R b/R/LearnerClustAffinityPropagation.R index 1b17f36..8a6209d 100644 --- a/R/LearnerClustAffinityPropagation.R +++ b/R/LearnerClustAffinityPropagation.R @@ -75,7 +75,7 @@ LearnerClustAP = R6Class("LearnerClustAP", rbind(exemplar_data, d), sel = (seq_len(nrow(d))) + nrow(exemplar_data) )[seq_len(nrow(exemplar_data)), ] - partition = unname(apply(sim_mat, 2, which.max)) + partition = unname(apply(sim_mat, 2L, which.max)) PredictionClust$new(task = task, partition = partition) } ) diff --git a/R/LearnerClustAgnes.R b/R/LearnerClustAgnes.R index 4dcb9e2..158705c 100644 --- a/R/LearnerClustAgnes.R +++ b/R/LearnerClustAgnes.R @@ -80,7 +80,7 @@ LearnerClustAgnes = R6Class("LearnerClustAgnes", .predict = function(task) { pv = self$param_set$get_values(tags = "predict") if (pv$k > task$nrow) { - stopf("`k` needs to be between 1 and %i", task$nrow) + stopf("`k` needs to be between 1 and %i.", task$nrow) } warn_prediction_useless(self$id) diff --git a/R/LearnerClustDiana.R b/R/LearnerClustDiana.R index 1ad446e..3fe60bc 100644 --- a/R/LearnerClustDiana.R +++ b/R/LearnerClustDiana.R @@ -61,7 +61,7 @@ LearnerClustDiana = R6Class("LearnerClustDiana", .predict = function(task) { pv = self$param_set$get_values(tags = "predict") if (pv$k > task$nrow) { - stopf("`k` needs to be between 1 and %s", task$nrow) + stopf("`k` needs to be between 1 and %i.", task$nrow) } warn_prediction_useless(self$id) diff --git a/R/LearnerClustFeatureless.R b/R/LearnerClustFeatureless.R index 1b8321c..ed9aa56 100644 --- a/R/LearnerClustFeatureless.R +++ b/R/LearnerClustFeatureless.R @@ -39,7 +39,7 @@ LearnerClustFeatureless = R6Class("LearnerClustFeatureless", n = task$nrow if (k > n) { - stopf("number of clusters must lie between 1 and nrow(data)") + stopf("number of clusters must lie between 1 and `nrow(data)`.") } partition = chunk(n, n_chunks = k) diff --git a/R/LearnerClustHclust.R b/R/LearnerClustHclust.R index c1348b8..8b3a042 100644 --- a/R/LearnerClustHclust.R +++ b/R/LearnerClustHclust.R @@ -73,7 +73,7 @@ LearnerClustHclust = R6Class("LearnerClustHclust", .predict = function(task) { pv = self$param_set$get_values(tags = "predict") if (pv$k > task$nrow) { - stopf("`k` needs to be between 1 and %i", task$nrow) + stopf("`k` needs to be between 1 and %i.", task$nrow) } warn_prediction_useless(self$id) diff --git a/R/LearnerClustMeanShift.R b/R/LearnerClustMeanShift.R index d3ad614..5b46705 100644 --- a/R/LearnerClustMeanShift.R +++ b/R/LearnerClustMeanShift.R @@ -52,7 +52,7 @@ LearnerClustMeanShift = R6Class("LearnerClustMeanShift", .train = function(task) { pv = self$param_set$get_values(tags = "train") if (!is.null(pv$subset) && length(pv$subset) > task$nrow) { - stopf("`subset` length must be less than or equal to number of observations in task") + stopf("`subset` length must be less than or equal to number of observations in task.") } m = invoke(LPCM::ms, X = task$data(), .args = pv) diff --git a/R/LearnerClustMiniBatchKMeans.R b/R/LearnerClustMiniBatchKMeans.R index d4dc2d6..007ea31 100644 --- a/R/LearnerClustMiniBatchKMeans.R +++ b/R/LearnerClustMiniBatchKMeans.R @@ -63,7 +63,7 @@ LearnerClustMiniBatchKMeans = R6Class("LearnerClustMiniBatchKMeans", pv = self$param_set$get_values(tags = "train") assert_centers_param(pv$CENTROIDS, task, test_matrix, "CENTROIDS") if (test_matrix(pv$CENTROIDS) && nrow(pv$CENTROIDS) != pv$clusters) { - stopf("`CENTROIDS` must have same number of rows as `clusters`") + stopf("`CENTROIDS` must have same number of rows as `clusters`.") } data = task$data() diff --git a/R/LearnerClustPAM.R b/R/LearnerClustPAM.R index 19d521c..ab3195d 100644 --- a/R/LearnerClustPAM.R +++ b/R/LearnerClustPAM.R @@ -59,8 +59,9 @@ LearnerClustPAM = R6Class("LearnerClustPAM", stopf("number of `medoids`' needs to match `k`!") } if (sum(pv$medoids <= task$nrow & pv$medoids >= 1L) != pv$k) { - msg = sprintf("`medoids` need to contain valid indices from 1") - stopf("%s to %s (number of observations)!", msg, pv$k) + stopf( + "`medoids` need to contain valid indices from 1 to %i (number of observations)!", pv$k + ) } } diff --git a/R/PredictionDataClust.R b/R/PredictionDataClust.R index 80854b5..bf790ca 100644 --- a/R/PredictionDataClust.R +++ b/R/PredictionDataClust.R @@ -55,7 +55,7 @@ c.PredictionDataClust = function(..., keep_duplicates = TRUE) { predict_types = names(mlr_reflections$learner_predict_types$clust) predict_types = map(dots, function(x) intersect(names(x), predict_types)) if (!every(predict_types[-1L], setequal, y = predict_types[[1L]])) { - stopf("Cannot combine predictions: Different predict types") + stopf("Cannot combine predictions: Different predict types.") } elems = c("row_ids", "partition") diff --git a/R/as_prediction_clust.R b/R/as_prediction_clust.R index c399278..2d19532 100644 --- a/R/as_prediction_clust.R +++ b/R/as_prediction_clust.R @@ -48,12 +48,13 @@ as_prediction_clust.data.frame = function(x, ...) { # nolint assert_names(names(x), must.include = c("row_ids", "partition")) prob_cols = setdiff(names(x), c("row_ids", "partition")) - if (length(prob_cols)) { + if (length(prob_cols) > 0L) { if (!all(startsWith(prob_cols, "prob."))) { - stopf("Table may only contain columns 'row_ids', 'partition' as well as columns prefixed with 'prob.' for class probabilities") # nolint + stopf("Table may only contain columns 'row_ids', 'partition' as well as columns prefixed with 'prob.' for class probabilities.") # nolint } prob = as.matrix(x[, prob_cols, with = FALSE]) - colnames(prob) = substr(colnames(prob), 6L, nchar(colnames(prob))) + nms = colnames(prob) + colnames(prob) = substr(nms, 6L, nchar(nms)) } else { prob = NULL } diff --git a/R/as_task_clust.R b/R/as_task_clust.R index 771bdca..2539e41 100644 --- a/R/as_task_clust.R +++ b/R/as_task_clust.R @@ -34,7 +34,7 @@ as_task_clust.data.frame = function(x, id = deparse1(substitute(x)), ...) { # no force(id) ii = which(map_lgl(keep(x, is.double), anyInfinite)) - if (length(ii)) { + if (length(ii) > 0L) { warningf("Detected columns with unsupported Inf values in data: %s", str_collapse(names(ii))) } @@ -59,7 +59,7 @@ as_task_clust.formula = function(x, data, id = deparse1(substitute(data)), ...) assert_data_frame(data) assert_subset(all.vars(x), c(names(data), "."), .var.name = "formula") if (attributes(terms(x, data = data))$response) { - stopf("Formula %s has a response", format(x)) + stopf("Formula %s has a response.", format(x)) } tab = model.frame(x, data, na.action = "na.pass") attr(tab, "terms") = attr(tab, "na.action") = NULL diff --git a/R/zzz.R b/R/zzz.R index 3a6cdf3..beffa74 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -14,12 +14,12 @@ mlr3cluster_tasks = new.env() mlr3cluster_learners = new.env() register_task = function(name, constructor) { - if (name %chin% names(mlr3cluster_tasks)) stopf("task %s registered twice", name) + if (name %chin% names(mlr3cluster_tasks)) stopf("task %s registered twice.", name) mlr3cluster_tasks[[name]] = constructor } register_learner = function(name, constructor) { - if (name %chin% names(mlr3cluster_learners)) stopf("learner %s registered twice", name) + if (name %chin% names(mlr3cluster_learners)) stopf("learner %s registered twice.", name) mlr3cluster_learners[[name]] = constructor }