File: setValueCNames.R

package info (click to toggle)
r-cran-paramhelpers 1.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 992 kB
  • sloc: ansic: 102; sh: 13; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 766 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#' @title Set components names for vector names
#'
#' @description
#' If param has `cnames` set component names in a value.
#' Otherwise `x` is left unchanged.
#'
#' @template arg_par_or_set
#' @param x (any) \cr
#'   Param value(s).
#'   For a parameter set this must be a list in the correct order.
#' @return `x` with changed names.
#' @export
setValueCNames = function(par, x) {
  UseMethod("setValueCNames")
}

#' @export
setValueCNames.Param = function(par, x) {
  # do not set names for missing / req.params
  if (par$type %fin% ph$value.component.names && !isScalarNA(x)) {
    names(x) = par$cnames
  }
  return(x)
}

#' @export
setValueCNames.ParamSet = function(par, x) {
  assertList(x, len = length(par$pars))
  Map(setValueCNames.Param, par$pars, x)
}