Skip to content

Commit 2c3b739

Browse files
committed
export convert_xy_to_form_*() functions
1 parent 056b459 commit 2c3b739

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ export(control_parsnip)
127127
export(convert_form_to_xy_fit)
128128
export(convert_form_to_xy_new)
129129
export(convert_stan_interval)
130+
export(convert_xy_to_form_fit)
131+
export(convert_xy_to_form_new)
130132
export(decision_tree)
131133
export(eval_args)
132134
export(fit)

R/convert_data.R

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# ------------------------------------------------------------------------------
22

3-
#' Helper functions to convert from formula to matrix interface
3+
#' Helper functions to convert between formula and matrix interface
44
#'
55
#' Functions to take a formula interface and get the resulting
6-
#' objects (y, x, weights, etc) back. For the most part, this
7-
#' emulates the internals of `lm` (and also see the notes at
6+
#' objects (y, x, weights, etc) back or the other way around. The functions are
7+
#' intended for developer use. For the most part, this emulates the internals
8+
#' of `lm` (and also see the notes at
89
#' https://developer.r-project.org/model-fitting-functions.html).
910
#'
10-
#' `convert_form_to_xy_fit` is for when the data are created for modeling.
11-
#' It saves both the data objects as well as the objects needed when new data
12-
#' are predicted (e.g. `terms`, etc.).
11+
#' `convert_form_to_xy_fit()` and `convert_xy_to_form_fit()` are for when the
12+
#' data are created for modeling.
13+
#' `convert_form_to_xy_fit()` saves both the data objects as well as the objects
14+
#' needed when new data are predicted (e.g. `terms`, etc.).
1315
#'
14-
#' `convert_form_to_xy_new` is used when new samples are being predicted and
15-
#' only requires the predictors to be available.
16+
#' `convert_form_to_xy_new()` and `convert_xy_to_form_new()` are used when new
17+
#' samples are being predicted and only require the predictors to be available.
1618
#'
1719
#' @param data A data frame containing all relevant variables (e.g. outcome(s),
1820
#' predictors, case weights, etc).
@@ -155,6 +157,7 @@ convert_form_to_xy_fit <- function(formula,
155157

156158

157159
#' @param object An object of class `model_fit`.
160+
#' @inheritParams predict.model_fit
158161
#' @rdname convert_helpers
159162
#' @keywords internal
160163
#' @export
@@ -230,9 +233,21 @@ convert_form_to_xy_new <- function(object,
230233
# The other direction where we make a formula from the data
231234
# objects
232235

233-
#' @importFrom dplyr bind_cols
234236
# TODO slots for other roles
235-
convert_xy_to_form_fit <- function(x, y, weights = NULL, y_name = "..y",
237+
#' @param weights A numeric vector containing the weights.
238+
#' @param y_name A string specifying the name of the outcome.
239+
#' @inheritParams fit.model_spec
240+
#' @inheritParams convert_form_to_xy_fit
241+
#'
242+
#' @rdname convert_helpers
243+
#' @keywords internal
244+
#' @export
245+
#'
246+
#' @importFrom dplyr bind_cols
247+
convert_xy_to_form_fit <- function(x,
248+
y,
249+
weights = NULL,
250+
y_name = "..y",
236251
remove_intercept = TRUE) {
237252
if (is.vector(x))
238253
rlang::abort("`x` cannot be a vector.")
@@ -279,6 +294,9 @@ convert_xy_to_form_fit <- function(x, y, weights = NULL, y_name = "..y",
279294
res
280295
}
281296

297+
#' @rdname convert_helpers
298+
#' @keywords internal
299+
#' @export
282300
convert_xy_to_form_new <- function(object, new_data) {
283301
new_data <- new_data[, object$x_var, drop = FALSE]
284302
if (!is.data.frame(new_data))

man/convert_helpers.Rd

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

0 commit comments

Comments
 (0)