atorus-research / Tplyr

Home Page:https://atorus-research.github.io/Tplyr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ellipsis arguments aren't unpackable outside of `add_layer()`

mstackhouse opened this issue · comments

This circumstance popped up with set_format_strings() acting differently in add_layer() and add_layers()

# Define a list of f_str's
num_formats <- list(
  "N"         = f_str("xx", n),
  "Mean (SD)" = f_str("xx.x (xx.xx)", mean, sd),
  "Median"    = f_str("xx.x", median),
  "Q1"        = f_str("xx", q1),
  "Q3"        = f_str("xx", q3),
  "Min"       = f_str("xx", min),
  "Max"       = f_str("xx", max)
)

# `add_layers()` example, create the tplyr_table
t <- tplyr_table(adsl, TRT01P)

# This won't work - Error in !num_formats : invalid argument type
l <- group_desc(t, AGE) %>%
  set_format_strings(!!!num_formats)

# Creating the same layer inside `add_layer()` will work fine
tplyr_table(adsl, TRT01P) %>%
  add_layer(
    group_desc(AGE) %>% 
      set_format_strings(!!!num_formats)
  ) %>% 
  build()

This can be resolved by using rlang::list2() here:

format_strings <- list(...)

This has a larger scope, as it may impact several other functions with an ellipsis argument where we're not explicitly capturing quosures.