splice {rlang}R Documentation

Splice lists

Description

[Questioning]

Usage

splice(x)

is_spliced(x)

is_spliced_bare(x)

dots_splice(
  ...,
  .ignore_empty = c("trailing", "none", "all"),
  .preserve_empty = FALSE,
  .homonyms = c("keep", "first", "last", "error"),
  .check_assign = FALSE
)

Arguments

x

A list to splice.

...

Arguments to collect in a list. These dots are dynamic.

.ignore_empty

Whether to ignore empty arguments. Can be one of "trailing", "none", "all". If "trailing", only the last argument is ignored if it is empty.

.preserve_empty

Whether to preserve the empty arguments that were not ignored. If TRUE, empty arguments are stored with missing_arg() values. If FALSE (the default) an error is thrown when an empty argument is detected.

.homonyms

How to treat arguments with the same name. The default, "keep", preserves these arguments. Set .homonyms to "first" to only keep the first occurrences, to "last" to keep the last occurrences, and to "error" to raise an informative error and indicate what arguments have duplicated names.

.check_assign

Whether to check for ⁠<-⁠ calls. When TRUE a warning recommends users to use = if they meant to match a function parameter or wrap the ⁠<-⁠ call in curly braces otherwise. This ensures assignments are explicit.

Standard splicing versus quoting splicing

The ⁠!!!⁠ operator works differently in standard functions taking dots with dots_list() than in quoting functions taking dots with enexprs() or enquos().

Most of the time you should not care about the difference. However if you use a standard function taking tidy dots within a quoting function, the ⁠!!!⁠ operator will disaggregate its argument because the behaviour of the quasiquoting function has priority. You might then observe some performance cost in edge cases. Here is one example where this would happen:

purrr::rerun(10, dplyr::bind_rows(!!! x))

purrr::rerun() is a quoting function and dplyr::bind_rows() is a standard function. Because bind_rows() is called inside rerun(), the list x will be disaggregated into a pairlist of arguments. To avoid this you can use splice() instead:

purrr::rerun(10, dplyr::bind_rows(splice(x)))

Life cycle


[Package rlang version 1.0.6 Index]