Skip to content

Commit 849ff1b

Browse files
committed
moved to separate file to get S3 docs in right order
1 parent 74ff766 commit 849ff1b

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

R/aaa_multi_predict.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Define a generic to make multiple predictions for the same model object ------
2+
3+
#' Model predictions across many sub-models
4+
#'
5+
#' For some models, predictions can be made on sub-models in the model object.
6+
#' @param object A `model_fit` object.
7+
#' @param ... Optional arguments to pass to `predict.model_fit(type = "raw")`
8+
#' such as `type`.
9+
#' @return A tibble with the same number of rows as the data being predicted.
10+
#' Mostly likely, there is a list-column named `.pred` that is a tibble with
11+
#' multiple rows per sub-model.
12+
#' @export
13+
multi_predict <- function(object, ...) {
14+
if (inherits(object$fit, "try-error")) {
15+
warning("Model fit failed; cannot make predictions.", call. = FALSE)
16+
return(NULL)
17+
}
18+
UseMethod("multi_predict")
19+
}
20+
21+
#' @export
22+
#' @rdname multi_predict
23+
multi_predict.default <- function(object, ...)
24+
stop("No `multi_predict` method exists for objects with classes ",
25+
paste0("'", class(), "'", collapse = ", "), call. = FALSE)
26+
27+
#' @export
28+
predict.model_spec <- function(object, ...) {
29+
stop("You must use `fit()` on your model specification before you can use `predict()`.", call. = FALSE)
30+
}

R/predict.R

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -231,33 +231,3 @@ prepare_data <- function(object, new_data) {
231231
new_data
232232
}
233233

234-
# Define a generic to make multiple predictions for the same model object ------
235-
236-
#' Model predictions across many sub-models
237-
#'
238-
#' For some models, predictions can be made on sub-models in the model object.
239-
#' @param object A `model_fit` object.
240-
#' @param ... Optional arguments to pass to `predict.model_fit(type = "raw")`
241-
#' such as `type`.
242-
#' @return A tibble with the same number of rows as the data being predicted.
243-
#' Mostly likely, there is a list-column named `.pred` that is a tibble with
244-
#' multiple rows per sub-model.
245-
#' @export
246-
multi_predict <- function(object, ...) {
247-
if (inherits(object$fit, "try-error")) {
248-
warning("Model fit failed; cannot make predictions.", call. = FALSE)
249-
return(NULL)
250-
}
251-
UseMethod("multi_predict")
252-
}
253-
254-
#' @export
255-
#' @rdname multi_predict
256-
multi_predict.default <- function(object, ...)
257-
stop("No `multi_predict` method exists for objects with classes ",
258-
paste0("'", class(), "'", collapse = ", "), call. = FALSE)
259-
260-
#' @export
261-
predict.model_spec <- function(object, ...) {
262-
stop("You must use `fit()` on your model specification before you can use `predict()`.", call. = FALSE)
263-
}

0 commit comments

Comments
 (0)