-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* faster * extend tests a little * minor improvements * document * more efficient deps handling in PSC * fix ps_union * transparent tags * dynamic tags shadow * avoid some instantiation of tags * renaming param to prevent misuse * trying to make R 4 tests work * testing shadow tags * tag shadows work with adds / removes * Towards S3 Params tuning sets and ParamSetCollection still missing * some fixes * a few fixes * a few fixes * quality of life stuff: set6 cache, domain class propreties, init values * some reorg * PSC & PSC trafos * relatively done with PSC * psc should be feature complete now * remove 'describe_error' * minor fixes * experiments * solution demo * progress * condition as S3 * Param.R -> Domain_methods.R * S6ObjectCache is pretty cool but we don't need it * domain -> Domain * for domain methods: default -> Domain * cleaning up * "feature complete" * more efficient tags * rename package * some bugfixes * qiute some progress * commit message * tests pass * S3 consistency * tests pass * trafo info flags * news and docs * rename back to 'paradox' * vignette progress * vignette builds * rd_info repair * work with bbotk * PSC * bugfix * checking strict now * handle requirements as in current paradox * documentation * small correction in doc * document * fix in examples * fix in examples II * document domain_-functions * document() * clean up documentation * document() * some more small doc fixes * document() --------- Co-authored-by: mb706 <mlr.developer@mb706.com>
- Loading branch information
Showing
111 changed files
with
4,210 additions
and
3,936 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,113 @@ | ||
# -- class methods | ||
|
||
#' @describeIn Condition | ||
#' | ||
#' Used internally. Tests whether a value satisfies a given condition. | ||
#' Vectorizes when `x` is atomic. | ||
#' | ||
#' @param cond (`Condition`)\cr | ||
#' `Condition` to use | ||
#' @param x (`any`)\cr | ||
#' Value to test | ||
condition_test = function(cond, x) { | ||
UseMethod("condition_test") | ||
} | ||
|
||
#' @describeIn Condition | ||
#' | ||
#' Used internally. Returns a string that represents the condition for pretty | ||
#' printing, in the form `"<lhs> <relation> <rhs>"`, e.g. `"x == 3"` or | ||
#' `"param %in% {1, 2, 10}"`. | ||
#' | ||
#' @param cond (`Condition`)\cr | ||
#' `Condition` to use | ||
#' @param lhs_chr (`character(1)`)\cr | ||
#' Symbolic representation to use for `<lhs>` in the returned string. | ||
#' @export | ||
condition_as_string = function(cond, lhs_chr = "x") { | ||
assert_string(lhs_chr) | ||
UseMethod("condition_as_string") | ||
} | ||
|
||
# -- Condition | ||
|
||
#' @title Dependency Condition | ||
#' | ||
#' @description | ||
#' Condition object, to specify the condition in a dependency. | ||
#' | ||
#' @param rhs (`any`)\cr | ||
#' Right-hand-side of the condition. | ||
#' @param condition_format_string (`character(1)`)\cr | ||
#' Format-string for representing the condition when pretty-printing | ||
#' in [`condition_as_string()`]. | ||
#' Should contain two `%s`, as it is used in an `sprintf()`-call with | ||
#' two further string values. | ||
#' | ||
#' @section Currently implemented simple conditions: | ||
#' * `CondEqual$new(rhs)` \cr | ||
#' Parent must be equal to `rhs`. | ||
#' * `CondAnyOf$new(rhs)` \cr | ||
#' Parent must be any value of `rhs`. | ||
#' * `CondEqual(rhs)` \cr | ||
#' Value must be equal to `rhs`. | ||
#' * `CondAnyOf(rhs)` \cr | ||
#' Value must be any value of `rhs`. | ||
#' | ||
#' @aliases CondEqual CondAnyOf | ||
#' @export | ||
Condition = R6Class("Condition", | ||
public = list( | ||
#' @field type (`character(1)`)\cr | ||
#' Name / type of the condition. | ||
type = NULL, | ||
#' @field rhs (`any`)\cr | ||
#' Right-hand-side of the condition. | ||
rhs = NULL, | ||
#' @description | ||
#' Creates a new instance of this [R6][R6::R6Class] class. | ||
#' | ||
#' @param type (`character(1)`)\cr | ||
#' Name / type of the condition. | ||
#' @param rhs (`any`)\cr | ||
#' Right-hand-side of the condition. | ||
initialize = function(type, rhs) { | ||
self$type = assert_string(type) | ||
self$rhs = rhs | ||
}, | ||
Condition = function(rhs, condition_format_string) { | ||
assert_string(condition_format_string) | ||
structure(list(rhs = rhs, condition_format_string = condition_format_string), class = "Condition") | ||
} | ||
|
||
#' @description | ||
#' Checks if condition is satisfied. | ||
#' Called on a vector of parent param values. | ||
#' | ||
#' @param x (`vector()`). | ||
#' @return `logical(1)`. | ||
test = function(x) stop("abstract"), | ||
#' @export | ||
condition_as_string.Condition = function(cond, lhs_chr = "x") { | ||
sprintf(cond$condition_format_string, lhs_chr, str_collapse(cond$rhs)) | ||
} | ||
|
||
#' @export | ||
format.Condition = function(x, ...) { | ||
sprintf("<Condition:%s>", class(x)[[1L]]) | ||
} | ||
|
||
#' @export | ||
print.Condition = function(x, ...) { | ||
catf("%s: %s", class(x)[[1L]], condition_as_string(x)) | ||
} | ||
|
||
#' @description | ||
#' Conversion helper for print outputs. | ||
#' @param lhs_chr (`character(1)`) | ||
as_string = function(lhs_chr = "x") { | ||
sprintf("%s %s %s", lhs_chr, self$type, str_collapse(self$rhs)) | ||
}, | ||
# -- CondEqual | ||
|
||
#' @description | ||
#' Helper for print outputs. | ||
#' @param ... (ignored). | ||
format = function(...) { | ||
sprintf("<%s:%s>", class(self)[1L], self$type) | ||
}, | ||
#' @export | ||
CondEqual = function(rhs) { | ||
assert_atomic(rhs, any.missing = FALSE, len = 1) | ||
cond = Condition(rhs, "%s == %s") | ||
set_class(cond, c("CondEqual", class(cond))) | ||
} | ||
|
||
#' @description | ||
#' Printer. | ||
#' | ||
#' @param ... (ignored). | ||
print = function(...) { | ||
catf("%s: %s", class(self)[1L], self$as_string()) | ||
} | ||
), | ||
) | ||
#' @export | ||
condition_test.CondEqual = function(cond, x) { | ||
!is.na(x) & x == cond$rhs | ||
} | ||
|
||
#' @export | ||
CondEqual = R6Class("CondEqual", inherit = Condition, | ||
public = list( | ||
initialize = function(rhs) { | ||
assert_atomic(rhs, any.missing = FALSE, len = 1) | ||
super$initialize("equal", rhs) | ||
}, | ||
test = function(x) !is.na(x) & x == self$rhs, | ||
as_string = function(lhs_chr = "x") sprintf("%s = %s", lhs_chr, as.character(self$rhs)) | ||
) | ||
) | ||
CondAnyOf = function(rhs) { | ||
assert_atomic(rhs, any.missing = FALSE, min.len = 1, unique = TRUE) | ||
cond = Condition(rhs, "%s %%in%% {%s}") | ||
set_class(cond, c("CondAnyOf", class(cond))) | ||
} | ||
|
||
#' @export | ||
CondAnyOf = R6Class("CondAnyOf", inherit = Condition, | ||
public = list( | ||
initialize = function(rhs) { | ||
assert_atomic(rhs, any.missing = FALSE, min.len = 1, unique = TRUE) | ||
super$initialize("anyof", rhs) | ||
}, | ||
test = function(x) !is.na(x) & x %in% self$rhs, | ||
as_string = function(lhs_chr = "x") sprintf("%s \u2208 {%s}", lhs_chr, str_collapse(self$rhs)) | ||
) | ||
) | ||
condition_test.CondAnyOf = function(cond, x) { | ||
!is.na(x) & x %in% cond$rhs | ||
} | ||
|
||
# FIXME: the following makes `condition$new()` possible for paradox transition | ||
# should give a deprecated warning at some point. | ||
#' @export | ||
`$.Constructor` = function(e1, e2) { | ||
if (!identical(e2, "new")) { | ||
stop("only 'new' element can be accessed.") | ||
} else { | ||
e1 | ||
} | ||
} | ||
|
||
CondEqual = structure(CondEqual, class = c("Constructor", "function")) | ||
CondAnyOf = structure(CondAnyOf, class = c("Constructor", "function")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.