Description Usage Arguments Value Note Examples
View source: R/arg-wrangling.R
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.
1 | args_and_kwargs(..., .already_quosure = FALSE)
|
... |
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) |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.