These options will be used on atomic types ("logical", "integer", "numeric", "complex", "character" and "raw")
Arguments
- ...
Should not be used. Forces passing arguments by name.
- trim
NULL
or integerish. Maximum of elements showed before it's trimmed. Note that it will necessarily produce code that doesn't reproduce the input. This code will parse without failure but its evaluation might fail.- fill
String. Method to use to represent the trimmed elements.
- compress
Boolean. It
TRUE
instead ofc()
Useseq()
,rep()
, or atomic constructorslogical()
,integer()
,numeric()
,complex()
,raw()
when relevant to simplify the output.- unicode_representation, escape
Deprecated, kept for compatibility with older versions. Overrides the arguments of
construct()
Details
If trim
is provided, depending on fill
we will present trimmed elements as followed:
"default"
: Use default atomic constructors, so for instancec("a", "b", "c")
might becomec("a", character(2))
."rlang"
: Use rlang atomic constructors, so for instancec("a", "b", "c")
might becomec("a", rlang::new_character(2))
, theserlang
constructors create vectors ofNAs
, so it's different from the default option."+"
: Use unary+
, so for instancec("a", "b", "c")
might becomec("a", +2)
."..."
: Use...
, so for instancec("a", "b", "c")
might becomec("a", ...)
"none"
: Don't represent trimmed elements.
Depending on the case some or all of the choices above might generate code that cannot be executed. The 2 former options above are the most likely to suceed and produce an output of the same type and dimensions recursively. This would at least be the case for data frame.
Examples
construct(iris, opts_atomic(trim = 2), check = FALSE) # fill = "default"
#> data.frame(
#> Sepal.Length = c(5.1, 4.9, numeric(148)),
#> Sepal.Width = c(3.5, 3, numeric(148)),
#> Petal.Length = c(1.4, 1.4, numeric(148)),
#> Petal.Width = c(0.2, 0.2, numeric(148)),
#> Species = factor(rep(c("setosa", "versicolor", character(1)), each = 50L))
#> )
construct(iris, opts_atomic(trim = 2, fill = "rlang"), check = FALSE)
#> data.frame(
#> Sepal.Length = c(5.1, 4.9, rlang::new_double(148)),
#> Sepal.Width = c(3.5, 3, rlang::new_double(148)),
#> Petal.Length = c(1.4, 1.4, rlang::new_double(148)),
#> Petal.Width = c(0.2, 0.2, rlang::new_double(148)),
#> Species = factor(rep(c("setosa", "versicolor", rlang::new_character(1)), each = 50L))
#> )
construct(iris, opts_atomic(trim = 2, fill = "+"), check = FALSE)
#> data.frame(
#> Sepal.Length = c(5.1, 4.9, +148),
#> Sepal.Width = c(3.5, 3, +148),
#> Petal.Length = c(1.4, 1.4, +148),
#> Petal.Width = c(0.2, 0.2, +148),
#> Species = factor(rep(c("setosa", "versicolor", +1), each = 50L))
#> )
construct(iris, opts_atomic(trim = 2, fill = "..."), check = FALSE)
#> data.frame(
#> Sepal.Length = c(5.1, 4.9, ...),
#> Sepal.Width = c(3.5, 3, ...),
#> Petal.Length = c(1.4, 1.4, ...),
#> Petal.Width = c(0.2, 0.2, ...),
#> Species = factor(rep(c("setosa", "versicolor", ...), each = 50L))
#> )
construct(iris, opts_atomic(trim = 2, fill = "none"), check = FALSE)
#> data.frame(
#> Sepal.Length = c(5.1, 4.9),
#> Sepal.Width = c(3.5, 3),
#> Petal.Length = c(1.4, 1.4),
#> Petal.Width = c(0.2, 0.2),
#> Species = factor(rep(c("setosa", "versicolor"), each = 50L))
#> )
construct(iris, opts_atomic(trim = 2, fill = "none"), check = FALSE)
#> data.frame(
#> Sepal.Length = c(5.1, 4.9),
#> Sepal.Width = c(3.5, 3),
#> Petal.Length = c(1.4, 1.4),
#> Petal.Width = c(0.2, 0.2),
#> Species = factor(rep(c("setosa", "versicolor"), each = 50L))
#> )
x <- c("a a", "a\U000000A0a", "a\U00002002a", "\U430 \U430")
construct(x, opts_atomic(unicode_representation = "unicode"))
#> c("a a", "a a", "a a", "а а")
construct(x, opts_atomic(unicode_representation = "character"))
#> c("a a", "a a", "a a", "а а")
construct(x, opts_atomic(unicode_representation = "latin"))
#> c("a a", "a a", "a\U{2002}a", "\U{430} \U{430}")
construct(x, opts_atomic(unicode_representation = "ascii"))
#> c("a a", "a\U{A0}a", "a\U{2002}a", "\U{430} \U{430}")