-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standardize group arguments in functions #105
Changes from 14 commits
86a0f0d
cc4a9c9
78b62cb
5ba17f5
044125a
6d7b5aa
5726549
99245e2
550fc5a
00ddfe3
adbda5d
d356a1b
65fe163
e7e7b2c
e992560
9627748
04d41fc
b4053ea
fd6c045
639d8b1
16760a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,6 @@ | |
cal_plot_breaks <- function(.data, | ||
truth = NULL, | ||
estimate = dplyr::starts_with(".pred"), | ||
group = NULL, | ||
num_breaks = 10, | ||
conf_level = 0.90, | ||
include_ribbon = TRUE, | ||
|
@@ -104,16 +103,16 @@ cal_plot_breaks <- function(.data, | |
cal_plot_breaks.data.frame <- function(.data, | ||
truth = NULL, | ||
estimate = dplyr::starts_with(".pred"), | ||
group = NULL, | ||
num_breaks = 10, | ||
conf_level = 0.90, | ||
include_ribbon = TRUE, | ||
include_rug = TRUE, | ||
include_points = TRUE, | ||
event_level = c("auto", "first", "second"), | ||
...) { | ||
|
||
check_cal_groups({{ group }}, .data) | ||
..., | ||
group = NULL) { | ||
check_group_argument({{ group }}, .data) | ||
.data <- dplyr::group_by(.data, dplyr::across({{ group }})) | ||
|
||
cal_plot_breaks_impl( | ||
.data = .data, | ||
|
@@ -134,23 +133,26 @@ cal_plot_breaks.data.frame <- function(.data, | |
cal_plot_breaks.tune_results <- function(.data, | ||
truth = NULL, | ||
estimate = dplyr::starts_with(".pred"), | ||
group = NULL, | ||
num_breaks = 10, | ||
conf_level = 0.90, | ||
include_ribbon = TRUE, | ||
include_rug = TRUE, | ||
include_points = TRUE, | ||
event_level = c("auto", "first", "second"), | ||
...) { | ||
if (rlang::quo_is_null(enquo(group))) { | ||
group <- expr(.config) | ||
} | ||
|
||
cal_plot_breaks_impl( | ||
tune_args <- tune_results_args( | ||
.data = .data, | ||
truth = {{ truth }}, | ||
estimate = {{ estimate }}, | ||
group = {{ group }}, | ||
event_level = event_level, | ||
... | ||
) | ||
|
||
cal_plot_breaks_impl( | ||
.data = tune_args$predictions, | ||
truth = !!tune_args$truth, | ||
estimate = !!tune_args$estimate, | ||
group = !!tune_args$group, | ||
Comment on lines
-146
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All |
||
num_breaks = num_breaks, | ||
conf_level = conf_level, | ||
include_ribbon = include_ribbon, | ||
|
@@ -293,7 +295,6 @@ cal_plot_breaks_impl <- function(.data, | |
.data = .data, | ||
truth = {{ truth }}, | ||
estimate = {{ estimate }}, | ||
group = {{ group }}, | ||
event_level = event_level, | ||
... | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
cal_plot_regression <- function(.data, | ||
truth = NULL, | ||
estimate = NULL, | ||
group = NULL, | ||
smooth = TRUE, | ||
...) { | ||
UseMethod("cal_plot_regression") | ||
|
@@ -37,11 +36,10 @@ cal_plot_regression <- function(.data, | |
cal_plot_regression_impl <- function(.data, | ||
truth = NULL, | ||
estimate = NULL, | ||
group = NULL, | ||
smooth = TRUE, | ||
...) { | ||
|
||
check_cal_groups({{ group }}, .data) | ||
..., | ||
group = NULL) { | ||
check_group_argument({{ group }}, .data) | ||
|
||
truth <- enquo(truth) | ||
estimate <- enquo(estimate) | ||
|
@@ -68,14 +66,12 @@ cal_plot_regression.data.frame <- cal_plot_regression_impl | |
cal_plot_regression.tune_results <- function(.data, | ||
truth = NULL, | ||
estimate = NULL, | ||
group = NULL, | ||
smooth = TRUE, | ||
...) { | ||
tune_args <- tune_results_args( | ||
.data = .data, | ||
truth = {{ truth }}, | ||
estimate = {{ estimate }}, | ||
group = {{ group }}, | ||
... | ||
) | ||
|
||
|
@@ -95,6 +91,10 @@ regression_plot_impl <- function(.data, truth, estimate, group, | |
estimate <- enquo(estimate) | ||
group <- enquo(group) | ||
|
||
if (quo_is_null(group)) { | ||
.data[[".config"]] <- NULL | ||
} | ||
Comment on lines
+94
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there isn't a group variable, e.i. This makes it easier to test that faceting isn't done with constant |
||
|
||
gp_vars <- dplyr::group_vars(.data) | ||
|
||
if (length(gp_vars)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,6 @@ process_level <- function(x) { | |
tune_results_args <- function(.data, | ||
truth, | ||
estimate, | ||
group, | ||
event_level, | ||
parameters = NULL, | ||
...) { | ||
|
@@ -239,7 +238,6 @@ tune_results_args <- function(.data, | |
|
||
truth <- enquo(truth) | ||
estimate <- enquo(estimate) | ||
group <- enquo(group) | ||
|
||
if (quo_is_null(truth)) { | ||
truth_str <- attributes(.data)$outcome | ||
|
@@ -250,15 +248,17 @@ tune_results_args <- function(.data, | |
estimate <- expr(dplyr::starts_with(".pred")) | ||
} | ||
|
||
if (quo_is_null(group)) { | ||
if (dplyr::n_distinct(.data[[".predictions"]][[1]][[".config"]]) > 1) { | ||
group <- quo(.config) | ||
} else { | ||
group <- quo(NULL) | ||
} | ||
Comment on lines
+251
to
255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the part that detects if there are more than 1 unique |
||
|
||
list( | ||
truth = quo(!!truth), | ||
estimate = quo(!!estimate), | ||
estimate = estimate, | ||
group = quo(!!group), | ||
group = group, | ||
predictions = predictions | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All
*.data.frame()
functions callscheck_group_argument()
and appliesdplyr::group_by()
with the group. This does nothing ifgroup = NULL