Skip to contents

These options will be used on atomic types ("logical", "integer", "numeric", "complex", "character" and "raw")

Usage

opts_atomic(
  ...,
  trim = NULL,
  fill = c("default", "rlang", "+", "...", "none"),
  compress = TRUE,
  unicode_representation = c("ascii", "latin", "character", "unicode"),
  escape = FALSE
)

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 of c() Use seq(), rep(), or atomic constructors logical(), integer(), numeric(), complex(), raw() when relevant to simplify the output.

unicode_representation

By default "ascii", which means only ASCII characters (code point < 128) will be used to construct a string. This makes sure that homoglyphs (different spaces and other identically displayed unicode characters) are printed differently, and avoid possible unfortunate copy and paste auto conversion issues. "latin" is more lax and uses all latin characters (code point < 256). "character" shows all characters, but not emojis. Finally "unicode" displays all characters and emojis, which is what dput() does.

escape

Whether to escape double quotes and backslashes. If FALSE we use single quotes to suround strings containing double quotes, and raw strings for strings that contain backslashes and/or a combination of single and double quotes. Depending on unicode_representation escape = FALSE cannot be applied on all strings.

Value

An object of class <constructive_options/constructive_options_atomic>

Details

If trim is provided, depending on fill we will present trimmed elements as followed:

  • "default" : Use default atomic constructors, so for instance c("a", "b", "c") might become c("a", character(2)).

  • "rlang" : Use rlang atomic constructors, so for instance c("a", "b", "c") might become c("a", rlang::new_character(2)), these rlang constructors create vectors of NAs, so it's different from the default option.

  • "+": Use unary +, so for instance c("a", "b", "c") might become c("a", +2).

  • "...": Use ..., so for instance c("a", "b", "c") might become c("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}")