-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
246 flexible delayed choices #247
246 flexible delayed choices #247
Conversation
@donyunardi please wait with the release until this is merged 👍 |
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.
first_choice
should be now:
first_choice <- function() {
out <- first_choices(1)
class(out) <- c("delayed_choices", "delayed_data")
out
}
No. There must be a distinction because the Allowing |
Sorry, I misread your comment. I think it's better to have independent implementations but if you prefer this way, I'll change it. |
I think there is even more room for improvement. All these functions repeat the same condition. Please create a private function which can evaluate custom functions:
.delayed_choices <- function(fun) {
structure(
function(x) {
if (inherits(x, "delayed_choices")) {
x
} else if (length(x) == 0L) {
x
} else if (is.atomic(x)) {
fun(x)
} else if (inherits(x, "delayed_data")) {
if (is.null(x$subset)) return(x)
original_fun <- x$subset
x$subset <- function(data) {
fun_x(original_fun(data))
}
x
}
},
class = c("delayed_choices", "delayed_data")
)
}
first_choices <- function(n) {
out <- .delayed_choices(fun = function(x) tail(x, n))
class(out) <- c("multiple_choices", class(out))
out
} |
Something like that was an idea I had but I didn't want to overcomplicate things prematurely 😉 |
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.
Great! 👍
Closes #246
Added functions
first_choices
andlast_choices
to allow for specifyingsubset
as "first n" and "last n" of available choices.Both functions take argument
n
which must be integer-line and greated than 1. This way specifyingfirst_choices(2)
automatically setsmultiple = TRUE
where appropriate.Class
all_choices
is changed to classmultiple_choices
.