File: simplifyMeasureNames.R

package info (click to toggle)
r-cran-mlr 2.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,264 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (24 lines) | stat: -rw-r--r-- 851 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
#' @title Simplify measure names.
#'
#' @description
#' Clips aggregation names from character vector.
#' E.g: 'mmce.test.mean' becomes 'mmce'.
#' Elements that don't contain a measure name are ignored and returned unchanged.
#'
#' @param xs ([character])\cr
#'   Character vector that (possibly) contains aggregated measure names.
#' @return ([character]).
#' @export
simplifyMeasureNames = function(xs) {

  assertCharacter(xs, any.missing = FALSE)
  # get all measure names
  all.measure.names = listMeasures()
  # cut everything after and including the first '.'
  xs.shortened = stri_replace_all_regex(xs, "\\..*", "")
  # check if this is a measure
  string.is.measure = (xs.shortened %in% all.measure.names)
  # if yes: insert shortened name, else insert original input
  res = ifelse(string.is.measure, xs.shortened, xs)
  as.character(res)
}