Skip to content

Commit

Permalink
refactor: add punctuation in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muecke committed Dec 4, 2024
1 parent 57c920b commit 2945eca
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion R/LearnerClustAffinityPropagation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustAgnes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustDiana.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustFeatureless.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustHclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustMeanShift.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustMiniBatchKMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions R/LearnerClustPAM.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/PredictionDataClust.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions R/as_prediction_clust.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions R/as_task_clust.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 2945eca

Please sign in to comment.