construct {constructive} | R Documentation |
Build code to recreate an object
Description
construct()
builds the code to reproduce one object, construct_multi()
builds the code to reproduce objects stored in a named list or environment.
Usage
construct(
x,
...,
data = NULL,
pipe = NULL,
check = NULL,
compare = compare_options(),
one_liner = FALSE,
template = getOption("constructive_opts_template")
)
construct_multi(
x,
...,
data = NULL,
pipe = NULL,
check = NULL,
compare = compare_options(),
one_liner = FALSE,
template = getOption("constructive_opts_template")
)
Arguments
x |
An object, for |
... |
Constructive options built with the |
data |
Named list or environment of objects we want to detect and mention by name (as opposed to deparsing them further). Can also contain unnamed nested lists, environments, or package names, in the latter case package exports and datasets will be considered. In case of conflict, the last provided name is considered. |
pipe |
Which pipe to use, either |
check |
Boolean. Whether to check if the created code reproduces the object
using |
compare |
Parameters passed to |
one_liner |
Boolean. Whether to collapse the output to a single line of code. |
template |
A list of constructive options built with |
Details
construct_multi()
recognizes promises, this means that for instance
construct_multi(environment())
can be called in a
function and will construct unevaluated arguments using delayedAssign()
.
Note however that construct_multi(environment())
is equivalent to construct_reprex()
called without argument and the latter is preferred.
Value
An object of class 'constructive'.
Constructive options
Constructive options provide a way to customize the output of 'construct()'. We can provide calls to 'opts_*()' functions to the '...' argument. Each of these functions targets a specific type or class and is documented on its own page.
-
opts_array(constructor = c("array", "next"), ...)
-
opts_AsIs(constructor = c("I", "next", "atomic"), ...)
-
opts_atomic(..., trim = NULL, fill = c("default", "rlang", "+", "...", "none"), compress = TRUE, unicode_representation = c("ascii", "latin", "character", "unicode"), escape = FALSE)
-
opts_classGeneratorFunction(constructor = c("setClass"), ...)
-
opts_classPrototypeDef(constructor = c("prototype"), ...)
-
opts_classRepresentation(constructor = c("getClassDef"), ...)
-
opts_constructive_options(constructor = c("opts", "next"), ...)
-
opts_data.frame(constructor = c("data.frame", "read.table", "next", "list"), ...)
-
opts_data.table(constructor = c("data.table", "next", "list"), ..., selfref = FALSE)
-
opts_Date(constructor = c("as.Date", "as_date", "date", "new_date", "as.Date.numeric", "as_date.numeric", "next", "atomic"), ..., origin = "1970-01-01")
-
opts_dm(constructor = c("dm", "next", "list"), ...)
-
opts_dots(constructor = c("default"), ...)
-
opts_environment(constructor = c(".env", "list2env", "as.environment", "new.env", "topenv", "new_environment"), ..., recurse = FALSE, predefine = FALSE)
-
opts_externalptr(constructor = c("default"), ...)
-
opts_factor(constructor = c("factor", "as_factor", "new_factor", "next", "atomic"), ...)
-
opts_formula(constructor = c("~", "formula", "as.formula", "new_formula", "next"), ..., environment = TRUE)
-
opts_function(constructor = c("function", "as.function", "new_function"), ..., environment = TRUE, srcref = FALSE, trim = NULL)
-
opts_grouped_df(constructor = c("default", "next", "list"), ...)
-
opts_language(constructor = c("default"), ...)
-
opts_Layer(constructor = c("default", "layer", "environment"), ...)
-
opts_list(constructor = c("list", "list2"), ..., trim = NULL, fill = c("vector", "new_list", "+", "...", "none"))
-
opts_matrix(constructor = c("matrix", "array", "next", "atomic"), ...)
-
opts_mts(constructor = c("ts", "next", "atomic"), ...)
-
opts_numeric_version(constructor = c("numeric_version", "next", "atomic"), ...)
-
opts_ordered(constructor = c("ordered", "factor", "new_ordered", "next", "atomic"), ...)
-
opts_package_version(constructor = c("package_version", "next", "atomic"), ...)
-
opts_pairlist(constructor = c("pairlist", "pairlist2"), ...)
-
opts_POSIXct(constructor = c("as.POSIXct", ".POSIXct", "as_datetime", "as.POSIXct.numeric", "as_datetime.numeric", "next", "atomic"), ..., origin = "1970-01-01")
-
opts_POSIXlt(constructor = c("as.POSIXlt", "next", "list"), ...)
-
opts_quosure(constructor = c("new_quosure", "next", "language"), ...)
-
opts_quosures(constructor = c("new_quosures", "next", "list"), ...)
-
opts_R_system_version(constructor = c("R_system_version", "next", "atomic"), ...)
-
opts_rowwise_df(constructor = c("default", "next", "list"), ...)
-
opts_S4(constructor = c("new"), ...)
-
opts_tbl_df(constructor = c("tibble", "tribble", "next", "list"), ..., trailing_comma = TRUE)
-
opts_ts(constructor = c("ts", "next", "atomic"), ...)
-
opts_vctrs_list_of(constructor = c("list_of", "list"), ...)
-
opts_weakref(constructor = c("new_weakref"), ...)
Examples
construct(head(cars))
construct(head(cars), opts_data.frame("read.table"))
construct(head(cars), opts_data.frame("next"))
construct(iris$Species)
construct(iris$Species, opts_atomic(compress = FALSE), opts_factor("new_factor"))