-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8093e41
commit 40bab52
Showing
5 changed files
with
76 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
#' Use orbital in a mutate way | ||
#' | ||
#' | ||
#' @param .data A data frame that can be used with mutate. | ||
#' @param x A orbital object. | ||
#' @param only_pred A logical value to determine if whole data set should be | ||
#' returned or just predictions. | ||
#' | ||
#' | ||
#' @returns A modified data frame. | ||
#' | ||
#' | ||
#' @examples | ||
#' library(workflows) | ||
#' library(recipes) | ||
#' library(parsnip) | ||
#' | ||
#' | ||
#' rec_spec <- recipe(mpg ~ ., data = mtcars) %>% | ||
#' step_normalize(all_numeric_predictors()) | ||
#' | ||
#' | ||
#' lm_spec <- linear_reg() | ||
#' | ||
#' | ||
#' wf_spec <- workflow(rec_spec, lm_spec) | ||
#' | ||
#' | ||
#' wf_fit <- fit(wf_spec, mtcars) | ||
#' | ||
#' | ||
#' orbital_obj <- orbital(wf_fit) | ||
#' | ||
#' | ||
#' mtcars %>% | ||
#' orbital_mutate(orbital_obj) | ||
#' | ||
#' mtcars %>% | ||
#' orbital_mutate(orbital_obj, only_pred = TRUE) | ||
#' orbital_predict(orbital_obj) | ||
#' @export | ||
orbital_mutate <- function(.data, x, only_pred = FALSE) { | ||
res <- dplyr::mutate(.data, !!!orbital_inline(x)) | ||
orbital_predict <- function(.data, x) { | ||
pred_name <- names(x)[length(x)] | ||
|
||
if (only_pred) { | ||
pred_name <- names(x)[length(x)] | ||
res <- dplyr::select(res, dplyr::any_of(pred_name)) | ||
} | ||
res <- dplyr::mutate(.data, !!!orbital_inline(x)) | ||
res <- dplyr::select(res, dplyr::any_of(pred_name)) | ||
|
||
res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' Use orbital in a mutate way | ||
#' | ||
#' @param .data A data frame that can be used with mutate. | ||
#' @param x A orbital object. | ||
#' | ||
#' @returns A modified data frame. | ||
#' | ||
#' @examples | ||
#' library(workflows) | ||
#' library(recipes) | ||
#' library(parsnip) | ||
#' | ||
#' rec_spec <- recipe(mpg ~ ., data = mtcars) %>% | ||
#' step_normalize(all_numeric_predictors()) | ||
#' | ||
#' lm_spec <- linear_reg() | ||
#' | ||
#' wf_spec <- workflow(rec_spec, lm_spec) | ||
#' | ||
#' wf_fit <- fit(wf_spec, mtcars) | ||
#' | ||
#' orbital_obj <- orbital(wf_fit) | ||
#' | ||
#' mtcars %>% | ||
#' orbital_predict(orbital_obj) | ||
#' @export | ||
orbital_predict <- function(.data, x) { | ||
res <- dplyr::mutate(.data, !!!orbital_inline(x)) | ||
|
||
pred_name <- names(x)[length(x)] | ||
res <- dplyr::select(res, dplyr::any_of(pred_name)) | ||
|
||
res | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters