args_and_kwargs | R Documentation |
*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.
This is useful for when you want these two types of arguments to behave differently. 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)
... |
Whatever mix of named and unnamed arguments you want |
.already_quosure |
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.
x <- args_and_kwargs(unnamed_1, named_1="ba", "unnamed_2", named_2 = letters) print(x$args) print(x$kwargs) # Or like how I made `share_scales` 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, ~quo_to_args(., akw$kwargs)) return(geoms) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.