11# ' @title Convert to a Forecast Task
22# '
33# ' @description
4- # ' Convert object to a [TaskRegr ].
4+ # ' Convert object to a [TaskFcst ].
55# ' This is a S3 generic. mlr3forecast ships with methods for the following objects:
66# '
7- # ' 1. [TaskRegr ]: ensure the identity
8- # ' 2. [data.frame()] and [DataBackend]: provides an alternative to the constructor of [TaskRegr ].
7+ # ' 1. [TaskFcst ]: ensure the identity
8+ # ' 2. [data.frame()] and [mlr3:: DataBackend]: provides an alternative to the constructor of [TaskFcst ].
99# '
10- # ' @inheritParams mlr3::as_task
11- # ' @param index (`character(1)`) the column name of the index.
12- # ' @param key (`character(1)`) the column name of the key.
10+ # ' @inheritParams mlr3::as_task_regr
11+ # ' @template param_order
12+ # ' @template param_key
1313# '
14- # ' @return [mlr3::TaskRegr ].
14+ # ' @return [TaskFcst ].
1515# ' @export
1616# ' @examplesIf requireNamespace("tsbox", quietly = TRUE)
1717# ' airpassengers = tsbox::ts_dt(AirPassengers)
1818# ' data.table::setnames(airpassengers, c("date", "passengers"))
19- # ' as_task_fcst(airpassengers, target = "passengers", index = "date")
19+ # ' as_task_fcst(airpassengers, target = "passengers", order = "date")
2020as_task_fcst = function (x , ... ) {
2121 UseMethod(" as_task_fcst" )
2222}
2323
24+ # ' @rdname as_task_fcst
25+ # ' @export
26+ as_task_regr.TaskFcst = function (x , clone = FALSE , ... ) { # nolint
27+ if (clone ) x $ clone() else x
28+ }
29+
2430# ' @rdname as_task_fcst
2531# ' @export
2632as_task_fcst.DataBackend = function (x , target = NULL , order = character (), key = character (), id = deparse1(substitute(x )), label = NA_character_ , ... ) { # nolint
@@ -33,19 +39,13 @@ as_task_fcst.DataBackend = function(x, target = NULL, order = character(), key =
3339 assert_choice(key , cn )
3440 }
3541
36- task = TaskFcst $ new(id = id , backend = x , target = target , order = order , label = label , ... )
37- task $ set_col_roles(key , add = " key" )
42+ task = TaskFcst $ new(
43+ id = id , backend = x , target = target , order = order , key = key , label = label , ...
44+ )
3845 task
3946}
4047
4148# ' @rdname as_task_fcst
42- # ' @template param_target
43- # ' @param id (`character(1)`)\cr
44- # ' Id for the new task.
45- # ' Defaults to the (deparsed and substituted) name of the data argument.
46- # ' @param index (`character(1)`)\cr
47- # ' Name of the column in the data containing the index.
48- # ' @template param_label
4949# ' @export
5050as_task_fcst.data.frame = function (x , target = NULL , order = character (), key = character (), id = deparse1(substitute(x )), label = NA_character_ , ... ) { # nolint
5151 force(id )
@@ -63,7 +63,8 @@ as_task_fcst.data.frame = function(x, target = NULL, order = character(), key =
6363 warningf(" Detected columns with unsupported Inf values in data: %s" , str_collapse(names(ii )))
6464 }
6565
66- task = TaskFcst $ new(id = id , backend = x , target = target , order = order , label = label , ... )
67- task $ set_col_roles(key , add = " key" )
66+ task = TaskFcst $ new(
67+ id = id , backend = x , target = target , order = order , key = key , label = label , ...
68+ )
6869 task
6970}
0 commit comments