Skip to content

Commit

Permalink
check fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Mar 3, 2024
1 parent 0376023 commit 4bfa78a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Minor changes:
to more easily label spikes. (#203; thanks @mattansb for the suggestion).
* The `arrow` parameter is now supported for intervals in `geom_slabinterval()`
(#206; thanks to @ASKurz for the suggestion).
* Optional arguments to automatically partially-applied functions can now be
passed a `waiver()` to use their default value (see `auto_partial()`).
* Several dependency reductions: removed {cowplot}, {purrr}, {forcats},
{palmerpenguins}, and {modelr} from *Suggests*; moved {tidyselect} and {dplyr}
from *Imports* to *Suggests*. The latter two are only strictly necessary for
Expand Down
21 changes: 10 additions & 11 deletions R/auto_partial.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,12 @@ auto_partial = function(f, name = NULL, waivable = TRUE) {
required_arg_names = required_arg_names[required_arg_names != "..."]

# build an expression to apply waivers to optional args
if (waivable) {
process_waivers = if (waivable) {
optional_args = f_args[!is_required_arg]
process_waivers = map2_(optional_args, names(optional_args), function(arg_expr, arg_name) {
map2_(optional_args, names(optional_args), function(arg_expr, arg_name) {
arg_sym = as.symbol(arg_name)
expr(if (inherits(!!arg_sym, "waiver")) !!arg_sym = !!arg_expr)
expr(if (inherits(!!arg_sym, "waiver")) (!!arg_name) = !!arg_expr)
})
} else {
process_waivers = list()
}

# build a logical expression testing to see if any required args are missing
Expand All @@ -189,18 +187,19 @@ auto_partial = function(f, name = NULL, waivable = TRUE) {
partial_self
}

if (length(required_arg_names) == 0) {
partial_self_if_missing_args = list()
} else {
partial_self_if_missing_args = list(expr(
partial_self_if_missing_args = if (length(required_arg_names) > 0) {
expr({
if (!!any_required_args_missing) return((!!partial_self_f)(!!name, waivable = !!waivable))
))
})
}

new_f = new_function(
f_args,
expr({
!!!process_waivers
# no idea why, but covr::package_coverage() fails if the next line doesn't
# have { } around it. It is not necessary for normal execution. Must have
# something to do with how covr adds hooks for tracing execution.
{ !!!process_waivers }
!!!partial_self_if_missing_args
!!!f_body
}),
Expand Down

0 comments on commit 4bfa78a

Please sign in to comment.