.cstr_apply {constructive}R Documentation

.cstr_apply

Description

Exported for custom constructor design. If recurse is TRUE (default), we recurse to construct args and insert their construction code in a fun(...) call returned as a character vector. If args already contains code rather than object to construct one should set recurse to FALSE.

Usage

.cstr_apply(
  args,
  fun = "list",
  ...,
  trailing_comma = FALSE,
  recurse = TRUE,
  implicit_names = FALSE,
  new_line = TRUE,
  one_liner = FALSE
)

Arguments

args

A list of arguments to construct recursively, or code if recurse = FALSE. If elements are named, the arguments will be named in the generated code.

fun

The function name to use to build code of the form "fun(...)"

...

options passed recursively to the further methods

trailing_comma

leave a trailing comma after the last argument if the code is multiline, some constructors allow it (e.g. tibble::tibble()) and it makes for nicer diffs in version control.

recurse

Whether to recursively generate the code to construct args. If FALSE arguments are expected to contain code.

implicit_names

When data is provided, compress calls of the form f(a = a) to f(a)

new_line

passed to wrap to remove add a line after "fun(" and before ")", forced to FALSE if one_liner is TRUE

one_liner

Whether to return a one line call.

Value

A character vector of code

Examples

a <- 1
.cstr_apply(list(a=a), "foo")
.cstr_apply(list(a=a), "foo", data = list(a=1))
.cstr_apply(list(a=a), "foo", data = list(a=1), implicit_names = TRUE)
.cstr_apply(list(b=a), "foo", data = list(a=1), implicit_names = TRUE)
.cstr_apply(list(a="c(1,2)"), "foo")
.cstr_apply(list(a="c(1,2)"), "foo", recurse = FALSE)

[Package constructive version 0.3.0 Index]