Skip to content

Commit

Permalink
ps_replicate prefixes -> affixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mb706 authored Aug 24, 2024
1 parent e19717b commit 844cd96
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions R/ps_replicate.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
#' [`ParamSet`] to use as template.
#' @param times (`integer(1)`)\cr
#' Number of times to repeat `set`.
#' Should not be given if `prefixes` is provided.
#' @param prefixes (`character`)\cr
#' A `character` vector indicating the prefixes to use for each repetition of `set`.
#' If this is given, `times` is inferred from `length(prefixes)` and should not be given separately.
#' Should not be given if `affixes` is provided.
#' @param affixes (`character`)\cr
#' A `character` vector indicating the prefixes / postfixes to use for each repetition of `set`.
#' Per default, these are prefixes; if `postfix` is `TRUE`, these values are postfixed instead.
#' If this is given, `times` is inferred from `length(affixes)` and should not be given separately.
#' If `times` is given, this defaults to `"repX"`, with `X` counting up from 1.
#' @param postfix (`logical(1)`)\cr
#' Whether to use `affixes` as a postfix instead of a prefix.
#' Default `FALSE` (use prefixes).
#' @param tag_sets (`logical(1)`)\cr
#' Whether to add a tag of the form `"set_<prefixes[[i]]>"` to each parameter in the result, indicating the repetition each parameter belongs to.
#' Whether to add a tag of the form `"set_<affixes[[i]]>"` to each parameter in the result, indicating the repetition each parameter belongs to.
#' @param tag_params (`logical(1)`)\cr
#' Whether to add a tag of the form `"param_<id>"` to each parameter in the result, indicating the original parameter ID inside `set`.
#' @examples
Expand All @@ -26,7 +30,9 @@
#'
#' ps_replicate(pset, 3)
#'
#' ps_replicate(pset, prefixes = c("first", "last"))
#' ps_replicate(pset, affixes = c("first", "last"))
#'
#' ps_replicate(pset, affixes = c("first", "last"), postfix = TRUE)
#'
#' pset$values = list(i = 1, z = FALSE)
#'
Expand All @@ -52,9 +58,9 @@
#' # get all values associated with the first repetition "rep1"
#' psr$get_values(any_tags = "set_rep1")
#' @export
ps_replicate = function(set, times = length(prefixes), prefixes = sprintf("rep%s", seq_len(times)), tag_sets = FALSE, tag_params = FALSE) {
ps_replicate = function(set, times = length(affixes), affixes = sprintf("rep%s", seq_len(times)), postfix = FALSE, tag_sets = FALSE, tag_params = FALSE) {
assert_count(times)
assert_character(prefixes, any.missing = FALSE, unique = TRUE, len = times)
assert_character(affixes, any.missing = FALSE, unique = TRUE, len = times)

ps_union(named_list(prefixes, set), tag_sets = tag_sets, tag_params = tag_params)
ps_union(named_list(affixes, set, postfix_names = postfix), tag_sets = tag_sets, tag_params = tag_params)
}

0 comments on commit 844cd96

Please sign in to comment.