Skip to content
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

Check prop argument #551

Merged
merged 4 commits into from
Sep 26, 2024
Merged

Check prop argument #551

merged 4 commits into from
Sep 26, 2024

Conversation

hfrick
Copy link
Member

@hfrick hfrick commented Sep 25, 2024

For #541 and #458

This PR reworks how the prop argument to various functions is checked.

Several of the functions had a written-out check block in either the user-facing function or the underlying *_split() function. The functions for grouped resampling were checking prop deep down the call chain with a check_prop().

I've decided to place the check in the user-facing functions and reworked it a little to benefit from the "friendly object type" in the standard checkers from rlang and only do the boundaries in a custom way.

check_prop <- function(prop, replace) {
acceptable_prop <- is.numeric(prop)
acceptable_prop <- acceptable_prop &&
((prop <= 1 && replace) || (prop < 1 && !replace))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This distinction between what the upper boundary can be is removed because we are using it only in group_boot_splits():

rsample/R/boot.R

Lines 264 to 265 in fe24aaa

prop = 1,
replace = TRUE,

We know where this particular prop = 1 is coming from and that it's okay in this context so the new check_prop() can just check user input.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saaaaaaaatisfying

@hfrick hfrick requested a review from simonpcouch September 25, 2024 16:35
Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade! Up! Grade!

check_prop <- function(prop, replace) {
acceptable_prop <- is.numeric(prop)
acceptable_prop <- acceptable_prop &&
((prop <= 1 && replace) || (prop < 1 && !replace))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saaaaaaaatisfying

R/misc.R Show resolved Hide resolved
tests/testthat/test-mc.R Show resolved Hide resolved
@hfrick hfrick merged commit 580a12f into main Sep 26, 2024
12 checks passed
@hfrick hfrick deleted the check-prop branch September 26, 2024 11:28
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants