diff --git a/DESCRIPTION b/DESCRIPTION index 288f93209..bb7badd18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -52,7 +52,7 @@ Imports: lgr (>= 0.3.4), mlbench, mlr3measures (>= 0.4.1), - mlr3misc (>= 0.12.0), + mlr3misc (>= 0.14.0), parallelly, palmerpenguins, paradox (>= 0.10.0), diff --git a/NEWS.md b/NEWS.md index e1274404e..d73918169 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # mlr3 (development version) +* feat: dictionary conversion of `mlr_learners` respects prototype arguments +recently added in mlr3misc + # mlr3 0.17.2 * Skip new `data.table` tests on mac. diff --git a/R/mlr_learners.R b/R/mlr_learners.R index c544ea25e..4ac19a432 100644 --- a/R/mlr_learners.R +++ b/R/mlr_learners.R @@ -45,7 +45,7 @@ as.data.table.DictionaryLearner = function(x, ..., objects = FALSE) { assert_flag(objects) setkeyv(map_dtr(x$keys(), function(key) { - l = withCallingHandlers(x$get(key), + l = withCallingHandlers(x$get(key, .prototype = TRUE), packageNotFoundWarning = function(w) invokeRestart("muffleWarning")) insert_named( list(key = key, label = l$label, task_type = l$task_type, feature_types = list(l$feature_types), packages = list(l$packages), diff --git a/tests/testthat/test_Dictionary.R b/tests/testthat/test_Dictionary.R index 98402030f..67a76ae37 100644 --- a/tests/testthat/test_Dictionary.R +++ b/tests/testthat/test_Dictionary.R @@ -9,3 +9,20 @@ test_that("Dictionary: clone works", { test_that("$keys(pattern) works", { expect_subset(mlr_learners$keys("classif"), mlr_learners$keys(), empty.ok = FALSE) }) + +test_that("dictionary to data.table conversion works with prototype arguments", { + LearnerRegrRpart2 = R6Class("LearnerRegrRpart2", + inherit = LearnerRegrRpart, + public = list( + x = NULL, + initialize = function(x) { + self$x = x + super$initialize() + } + ) + ) + on.exit(mlr_learners$remove("regr.rpart2")) + mlr_learners$add("regr.rpart2", LearnerRegrRpart2, .prototype_args = list(x = 123)) + + expect_data_table(as.data.table(mlr_learners)) +})