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

229 delayed_choices as single function #231

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

chlebowa
Copy link
Contributor

@chlebowa chlebowa commented Dec 18, 2024

Closes #229

CHANGES

Replaced all_choices with delayed_choices which allows to perform delayed selection of the first or the last element of choices, as well as all elements, maintaining all_choices functionality.

IMPLEMENTATION

delayed_choices returns a function that will add the appropriate subsetting operation to the function found in the $subset element of its delayed_data argument. Atomic arguments are returned as is.
The function has a class for easy identification.

if (inherits(selected) "delayed_choices") {
  selected <- selected(choices)              # modify delayed choices
} else {
  selected <- choices                        # use choices as is
}

Selecting all choices (delayed_choices("all")) is still a special case when checking arguments in some functions (choices vs multiple) so an extra class is added to delayed_choices functions to keep track of that.

NOTE

I thought about including the possibility of selecting the n-th element but I decided agains it. If the user knows that they want the n-th element speficically, they likely know what it is and can define it literally. Also, it opens the possibility of a range of elements (n:m) and that quickly escalates beyond reasonable granularity.
Let me know if you want an n-th choice option anyway, it can readily be added with this implementation.

ALTERNATIVE

See #232 for alternative implementation with separate functions.

Copy link
Contributor

github-actions bot commented Dec 18, 2024

✅ All contributors have signed the CLA
Posted by the CLA Assistant Lite bot.

@chlebowa
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@chlebowa chlebowa marked this pull request as draft December 18, 2024 17:31
@chlebowa chlebowa force-pushed the 229_delayed_choices@main branch from 5d17ca7 to d89ee0c Compare December 18, 2024 20:44
@chlebowa chlebowa marked this pull request as ready for review December 18, 2024 20:44
@gogonzo gogonzo self-assigned this Dec 19, 2024
@gogonzo gogonzo added the core label Dec 19, 2024
@chlebowa chlebowa changed the title 229 delayed_choices 229 delayed_choices as single function Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: add first_choice function
2 participants