Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify dots assertion #1241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/Learner.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Learner = R6Class("Learner",
start_learner = get_private(self$hotstart_stack)$.start_learner(self, task$hash)
}
if (is.null(self$hotstart_stack) || is.null(start_learner)) {
# no hotstart learners stored or no adaptable model found
# no hotstart learners stored or no adaptable model found
learner = self
mode = "train"
} else {
Expand Down
33 changes: 19 additions & 14 deletions R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test_matching_task_type = function(task_type, object, class) {
#' @param learners (list of [Learner]).
#' @rdname mlr_assertions
assert_learners = function(learners, task = NULL, task_type = NULL, properties = character(), unique_ids = FALSE, .var.name = vname(learners)) {
if (unique_ids) {
if (unique_ids) {
ids = map_chr(learners, "id")
if (!test_character(ids, unique = TRUE)) {
stopf("Learners need to have unique IDs: %s", str_collapse(ids))
Expand Down Expand Up @@ -416,18 +416,23 @@ assert_param_values = function(x, n_learners = NULL, .var.name = vname(x)) {
#' @return `NULL`
#' @export
assert_empty_ellipsis = function(...) {
if (...length()) {
names = ...names()
if (is.null(names)) {
stopf("Received %i unnamed argument that was not used.", ...length())
} else {
names2 = names[names != ""]
if (length(names2) == length(names)) {
stopf("Received the following named arguments that were unused: %s.", paste0(names2, collapse = ", "))
} else {
stopf("Received unused arguments: %i unnamed, as well as named arguments %s.", length(names) - length(names2), paste0(names2, collapse = ", "))
}
}
nx = ...length()
if (nx == 0L) {
return(NULL)
}
names = ...names()
if (is.null(names)) {
stopf("Received %i unnamed argument that was not used.", nx)
}
names2 = names[nzchar(names)]
if (length(names2) == length(names)) {
stopf(
"Received the following named arguments that were unused: %s.",
toString(names2)
)
}
NULL
stopf(
"Received unused arguments: %i unnamed, as well as named arguments %s.",
length(names) - length(names2), toString(names2)
)
}
Loading