Currently, set_contrasts and related functions can use external contrast coding schemes like so:
foo <- function(n) contr.sum(n)
foo2 <- function(n_levels) contr.sum(n_levels)
# Both of these are fine
set_contrasts(df, varName ~ foo)
set_contrasts(df, varName ~ foo2)
But if the named argument isn't n or n_levels then it doesn't work
such that if a function is passed, we can check whether n exists and if not, look up the name of the first parameter and set n_levels to that. Basically something like:
function_parameters <- names(formals(foo))
par_name <- "n"
if (!"n" %in% function_parameters)
par_name <- function_parameters[1L]
params <- setNames(list(n_levels), par_name)
Currently,
set_contrasts
and related functions can use external contrast coding schemes like so:But if the named argument isn't
n
orn_levels
then it doesn't workIn the definition for
.bundle_params()
, we can add the desired function as an optional argument then extend this block:such that if a function is passed, we can check whether
n
exists and if not, look up the name of the first parameter and setn_levels
to that. Basically something like: