File: setValueCNames.R

package info (click to toggle)
r-cran-paramhelpers 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 984 kB
  • sloc: ansic: 260; sh: 13; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 775 bytes parent folder | download
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
#' @title Set components names for vector names
#'
#' @description
#' If param has \code{cnames} set component names in a value.
#' Otherwise \code{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 \code{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)
}