@@ -375,14 +375,14 @@ Learner = R6Class("Learner",
375375 predict = function (task , row_ids = NULL ) {
376376 # improve error message for the common mistake of passing a data.frame here
377377 if (is.data.frame(task )) {
378- stopf (" To predict on data.frames, use the method `$predict_newdata()` instead of `$predict()`" )
378+ error_input (" To predict on data.frames, use the method `$predict_newdata()` instead of `$predict()`" )
379379 }
380380 task = assert_task(as_task(task ))
381381 assert_predictable(task , self )
382382 row_ids = assert_row_ids(row_ids , task = task , null.ok = TRUE )
383383
384384 if (is.null(self $ state $ model ) && is.null(self $ state $ fallback_state $ model )) {
385- stopf (" Cannot predict, Learner '%s' has not been trained yet" , self $ id )
385+ error_input (" Cannot predict, Learner '%s' has not been trained yet" , self $ id )
386386 }
387387
388388 # we need to marshal for call-r prediction and parallel prediction, but afterwards we reset the model
@@ -452,7 +452,7 @@ Learner = R6Class("Learner",
452452 predict_newdata = function (newdata , task = NULL ) {
453453 if (is.null(task )) {
454454 if (is.null(self $ state $ train_task )) {
455- stopf (" No task stored, and no task provided" )
455+ error_input (" No task stored, and no task provided" )
456456 }
457457 task = self $ state $ train_task $ clone()
458458 } else {
@@ -618,7 +618,7 @@ Learner = R6Class("Learner",
618618 fallback $ id , self $ id , str_collapse(missing_properties ), class = " Mlr3WarningConfigFallbackProperties" )
619619 }
620620 } else if (method == " none" && ! is.null(fallback )) {
621- stopf (" Fallback learner must be `NULL` if encapsulation is set to `none`." )
621+ error_input (" Fallback learner must be `NULL` if encapsulation is set to `none`." )
622622 }
623623
624624 private $ .encapsulation = c(train = method , predict = method )
@@ -665,7 +665,7 @@ Learner = R6Class("Learner",
665665 for (i in seq_along(new_values )) {
666666 nn = ndots [[i ]]
667667 if (! exists(nn , envir = self , inherits = FALSE )) {
668- stopf (" Cannot set argument '%s' for '%s' (not a parameter, not a field).%s" ,
668+ error_config (" Cannot set argument '%s' for '%s' (not a parameter, not a field).%s" ,
669669 nn , class(self )[1L ], did_you_mean(nn , c(param_ids , setdiff(names(self ), " .__enclos_env__" )))) # nolint
670670 }
671671 self [[nn ]] = new_values [[i ]]
@@ -681,10 +681,10 @@ Learner = R6Class("Learner",
681681 # ' If set to `"error"`, an error is thrown, otherwise all features are returned.
682682 selected_features = function () {
683683 if (is.null(self $ model )) {
684- stopf (" No model stored" )
684+ error_input (" No model stored" )
685685 }
686686 if (private $ .selected_features_impute == " error" ) {
687- stopf (" Learner does not support feature selection" )
687+ error_input (" Learner does not support feature selection" )
688688 } else {
689689 self $ state $ feature_names
690690 }
@@ -790,15 +790,15 @@ Learner = R6Class("Learner",
790790
791791 assert_string(rhs , .var.name = " predict_type" )
792792 if (rhs %nin % self $ predict_types ) {
793- stopf (" Learner '%s' does not support predict type '%s'" , self $ id , rhs )
793+ error_input (" Learner '%s' does not support predict type '%s'" , self $ id , rhs ) # TODO error_learner?
794794 }
795795 private $ .predict_type = rhs
796796 },
797797
798798 # ' @template field_param_set
799799 param_set = function (rhs ) {
800800 if (! missing(rhs ) && ! identical(rhs , private $ .param_set )) {
801- stopf (" param_set is read-only." )
801+ error_input (" param_set is read-only." )
802802 }
803803 private $ .param_set
804804 },
@@ -866,7 +866,7 @@ Learner = R6Class("Learner",
866866 # return: Numeric vector of weights or `no_weights_val` (default NULL)
867867 .get_weights = function (task , no_weights_val = NULL ) {
868868 if (" weights" %nin % self $ properties ) {
869- stop (" private$.get_weights should not be used in Learners that do not have the 'weights' property." )
869+ error_mlr3 (" private$.get_weights should not be used in Learners that do not have the 'weights' property." )
870870 }
871871 if (self $ use_weights == " use" && " weights_learner" %in% task $ properties ) {
872872 task $ weights_learner $ weight
@@ -916,7 +916,7 @@ default_values.Learner = function(x, search_space, task, ...) { # nolint
916916 values = default_values(x $ param_set )
917917
918918 if (any(search_space $ ids() %nin % names(values ))) {
919- stopf (" Could not find default values for the following parameters: %s" ,
919+ error_input (" Could not find default values for the following parameters: %s" ,
920920 str_collapse(setdiff(search_space $ ids(), names(values ))))
921921 }
922922
0 commit comments