File: checkTask.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 (20 lines) | stat: -rw-r--r-- 720 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
# performs arg checks of a task (or maybe also allow an taskdesc)
# you can check that the task is from a list of certain types
checkTask = function(x, cl = "Task", allow.desc = FALSE, task.type = NULL, binary = FALSE, .var.name = "task") {
  if (allow.desc) {
    assert(.var.name = .var.name,
      checkClass(x, classes = cl),
      checkClass(x, "TaskDesc")
    )
  } else {
    assertClass(x, classes = cl, .var.name = .var.name)
  }
  td = getTaskDesc(x)

  if (!is.null(task.type) && td$type %nin% task.type) {
    stopf("Task must be one of '%s', but is: '%s'", collapse(task.type), td$type)
  }
  if (binary && length(td$class.levels) != 2L) {
    stopf("Task '%s' must be binary classification!", td$id)
  }
}