args_and_kwargs {catchr}R Documentation

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

Description

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.

Usage

args_and_kwargs(..., .already_quosure = FALSE)

Arguments

...

Any mix of named and unnamed arguments

.already_quosure

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

Value

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.

Note

This function started out in the zplyr package.

Examples


x <- args_and_kwargs(unnamed_1, named_1="ba", "unnamed_2", named_2 = letters)
print(x$args)
print(x$kwargs)

## 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))
  return(geoms)
}

## End(Not run)

[Package catchr version 0.2.3 Index]