Skip to content

Commit 12fab1e

Browse files
committed
docs: better learner and task docs
1 parent eed3a0a commit 12fab1e

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
S3method(as_task_fcst,DataBackend)
44
S3method(as_task_fcst,data.frame)
5+
S3method(as_task_regr,TaskFcst)
56
export(ForecastLearner)
67
export(ForecastRecursiveLearner)
78
export(LearnerFcst)

R/TaskFcst.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#' @template seealso_task
1616
#' @export
1717
#' @examplesIf requireNamespace("tsbox", quietly = TRUE)
18-
#' airpassengers = tsbox::ts_dt(load_dataset("AirPassengers", "datasets"))
19-
#' setnames(airpassengers, c("date", "passengers"))
18+
#' airpassengers = tsbox::ts_dt(AirPassengers)
19+
#' data.table::setnames(airpassengers, c("date", "passengers"))
2020
#' task = as_task_fcst(airpassengers, target = "passengers", order = "date")
2121
#' task$task_type
2222
#' task$formula()

R/as_task_fcst.R

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
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")
2020
as_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
2632
as_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
5050
as_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
}

man/TaskFcst.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/as_task_fcst.Rd

Lines changed: 16 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)