Skip to content

Instantly share code, notes, and snippets.

@grayskripko
Last active June 28, 2024 20:15
Show Gist options
  • Save grayskripko/9890d31d534bd1a980f2699c00ed1cf7 to your computer and use it in GitHub Desktop.
Save grayskripko/9890d31d534bd1a980f2699c00ed1cf7 to your computer and use it in GitHub Desktop.
Parametrized function calls
expand_grid(
pick_n = 1:3) |>
rowwise() |>
mutate(mtr = unlist(list(measure(
sam_vos, n_weeks=4, fn = \(x) sort(x)[pick_n])))) |>
# OR unnamed
mutate(mtr = unlist(list(apply_to_wur(lst(across(ev()))))) |>
ungroup() |>
pprint()
# more: https://dplyr.tidyverse.org/articles/rowwise.html#repeated-function-calls
# previous
expand_grid(
fn = list(
mean=mean,
quant08=\(x) unname(quantile(x, probs = 0.8))),
chunk_size = seq(10, 50, by=20)) |>
# 1
group_by(i = row_number()) |>
nest() |>
mutate(data = map(data, ~{
cur <- .
unl <- map(cur, 1)
do.call(unl$det_type, args=c(
list(sale=pre_sel),
discard_at(unl, 'det_type'))) |>
measure() |>
curly(~bind_cols(cur, .))
}))
# 2
rowwise() |>
mutate(output = pmap(lst(
chunk_size, history, quantile, discount_threshold),
~measure(sale, partial(detect_promo, ...)) ))
# 3
rowwise() |>
mutate(scores=list(measure(detector$aware(
sale=pre_y, chunk_size = chunk_size, fn = fn))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment