File: simplifyMeasureNames.R

package info (click to toggle)
r-cran-mlr 2.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,760 kB
  • sloc: ansic: 65; sh: 13; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 850 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
#' @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)
}