diff --git a/.github/workflows/pkgdown.yml b/.github/workflows/pkgdown.yml index 0e935d7f2..9a21455dc 100644 --- a/.github/workflows/pkgdown.yml +++ b/.github/workflows/pkgdown.yml @@ -44,7 +44,7 @@ jobs: - name: Deploy if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@v4.6.9 + uses: JamesIves/github-pages-deploy-action@v4.7.2 with: clean: false branch: gh-pages diff --git a/DESCRIPTION b/DESCRIPTION index 8b61ae016..4109f29a7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -71,7 +71,7 @@ Suggests: remotes, RhpcBLASctl, rpart, - testthat (>= 3.1.0) + testthat (>= 3.2.0) Encoding: UTF-8 Config/testthat/edition: 3 Config/testthat/parallel: false diff --git a/R/Learner.R b/R/Learner.R index 72014c8f5..d1b7e7863 100644 --- a/R/Learner.R +++ b/R/Learner.R @@ -504,6 +504,50 @@ Learner = R6Class("Learner", private$.encapsulation = c(train = method, predict = method) private$.fallback = fallback + return(invisible(self)) + }, + + #' @description + #' Sets parameter values and fields of the learner. + #' All arguments whose names match the name of a parameter of the [paradox::ParamSet] are set as parameters. + #' All remaining arguments are assumed to be regular fields. + #' + #' @param ... (named `any`)\cr + #' Named arguments to set parameter values and fields. + #' @param .values (named `any`)\cr + #' Named list of parameter values and fields. + configure = function(..., .values = list()) { + dots = list(...) + assert_list(dots, names = "unique") + assert_list(.values, names = "unique") + assert_disjunct(names(dots), names(.values)) + new_values = insert_named(dots, .values) + + # set params in ParamSet + if (length(new_values)) { + param_ids = self$param_set$ids() + ii = names(new_values) %in% param_ids + if (any(ii)) { + self$param_set$values = insert_named(self$param_set$values, new_values[ii]) + new_values = new_values[!ii] + } + } else { + param_ids = character() + } + + # remaining args go into fields + if (length(new_values)) { + ndots = names(new_values) + for (i in seq_along(new_values)) { + nn = ndots[[i]] + if (!exists(nn, envir = self, inherits = FALSE)) { + stopf("Cannot set argument '%s' for '%s' (not a parameter, not a field).%s", + nn, class(self)[1L], did_you_mean(nn, c(param_ids, setdiff(names(self), ".__enclos_env__")))) # nolint + } + self[[nn]] = new_values[[i]] + } + } + return(invisible(self)) } ), diff --git a/inst/testthat/helper_expectations.R b/inst/testthat/helper_expectations.R index c7656defb..d6c2ca1b0 100644 --- a/inst/testthat/helper_expectations.R +++ b/inst/testthat/helper_expectations.R @@ -517,7 +517,7 @@ expect_measure = function(m) { testthat::expect_output(print(m), "Measure") if ("requires_no_prediction" %in% m$properties) { - testthat::expect_true(is.null(m$predict_sets)) + testthat::expect_null(m$predict_sets) } expect_id(m$id) diff --git a/man/Learner.Rd b/man/Learner.Rd index fee67c15a..f5ede1944 100644 --- a/man/Learner.Rd +++ b/man/Learner.Rd @@ -318,6 +318,7 @@ Stores \code{HotstartStack}.} \item \href{#method-Learner-reset}{\code{Learner$reset()}} \item \href{#method-Learner-base_learner}{\code{Learner$base_learner()}} \item \href{#method-Learner-encapsulate}{\code{Learner$encapsulate()}} +\item \href{#method-Learner-configure}{\code{Learner$configure()}} \item \href{#method-Learner-clone}{\code{Learner$clone()}} } } @@ -608,6 +609,29 @@ The fallback learner for failed predictions.} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Learner-configure}{}}} +\subsection{Method \code{configure()}}{ +Sets parameter values and fields of the learner. +All arguments whose names match the name of a parameter of the \link[paradox:ParamSet]{paradox::ParamSet} are set as parameters. +All remaining arguments are assumed to be regular fields. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Learner$configure(..., .values = list())}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{...}}{(named \code{any})\cr +Named arguments to set parameter values and fields.} + +\item{\code{.values}}{(named \code{any})\cr +Named list of parameter values and fields.} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Learner-clone}{}}} \subsection{Method \code{clone()}}{ diff --git a/man/LearnerClassif.Rd b/man/LearnerClassif.Rd index a62e3b668..64a29cf74 100644 --- a/man/LearnerClassif.Rd +++ b/man/LearnerClassif.Rd @@ -85,6 +85,7 @@ Other Learner:
Inherited methods