#' @title Regression Task
#'
#' @include TaskSupervised.R
#'
#' @description
#' This task specializes [Task] and [TaskSupervised] for regression problems.
#' The target column is assumed to be numeric.
#' The `task_type` is set to `"regr"`.
#'
#' It is recommended to use [as_task_regr()] for construction.
#' Predefined tasks are stored in the [dictionary][mlr3misc::Dictionary] [mlr_tasks].
#'
#' @template param_rows
#' @template param_id
#' @template param_backend
#'
#' @template seealso_task
#' @export
#' @examples
#' task = as_task_regr(mtcars, target = "mpg")
#' task$task_type
#' task$formula()
#' task$truth()
#' task$data(rows = 1:3, cols = task$feature_names[1:2])
TaskRegr = R6Class(
  "TaskRegr",
  inherit = TaskSupervised,
  public = list(
    #' @description
    #' Creates a new instance of this [R6][R6::R6Class] class.
    #' The function [as_task_regr()] provides an alternative way to construct regression tasks.
    #'
    #' @template param_target
    #' @template param_label
    #' @template param_extra_args
    initialize = function(id, backend, target, label = NA_character_, extra_args = list()) {
      assert_string(target)
      super$initialize(
        id = id,
        task_type = "regr",
        backend = backend,
        target = target,
        label = label,
        extra_args = extra_args
      )

      type = fget_key(self$col_info, i = target, j = "type", key = "id")
      if (type %nin% c("integer", "numeric")) {
        error_input("Target column '%s' must be numeric", target)
      }
    },

    #' @description
    #' True response for specified `row_ids`. Format depends on the task type.
    #' Defaults to all rows with role "use".
    #' @return `numeric()`.
    truth = function(rows = NULL) {
      super$truth(rows)[[1L]]
    }
  )
)
