args_and_kwargs {catchr}R Documentation

Separate dots into Python-esque *args and **kwargs


This function will return a named list with two sublists, 'args' and 'kwargs', which contain the unnamed and named arguments as quosures, respectively.

This is useful for when you want these two types of arguments to behave differently, e.g., as they do in make_plans(). The quosures will also have the attribute 'arg_pos', which will indicate their position in the original order in which they were supplied.


args_and_kwargs(..., .already_quosure = FALSE)



Any mix of named and unnamed arguments


if the arguments are already all quosures (in which case it will just sort them by named vs. unnamed arguments)


A named list of lists, with $args being a list of quosures of the unnamed arguments and $kwargs being a list of quosures of the named arguments.


This function started out in the zplyr package.


x <- args_and_kwargs(unnamed_1, named_1="ba", "unnamed_2", named_2 = letters)

## Not run: 
# Or see the `share_scales` from the `zplyr` package
share_scales <- function(...) {
  akw <- args_and_kwargs(...)
  # Unnamed arguments are ggplot scales
  geom_func_list <- purrr::map(akw$args, rlang::eval_tidy)
  # Named arguments are to be passed into those scales
  geoms <- purrr::map(geom_func_list, ~.(!!!akw$kwargs))

## End(Not run)

[Package catchr version 0.2.31 Index]