Learn R Programming

toscutil (version 2.8.0)

dput2: Return ASCII representation of an R object

Description

Like classic dput(), but instead of writing to stdout, the text representation is returned as string.

Usage

dput2(..., collapse = " ", trim = TRUE)

Value

If collapse == '\n', a character vector of length 1. Else, a character vector of length n, where n corresponds to the number of lines outputted by classic dput().

Arguments

...

Arguments passed on to dput().

collapse

Character to use for collapsing the lines.

trim

If TRUE, leading and trailing whitespace from each line is cleared before the lines are collapsed and/or returned.

See Also

Examples

Run this code
# Classic dput prints directly to stdout
x <- iris[1, ]
dput(x)

# Traditional formatting using dput2
y <- dput2(x, collapse = "\n", trim = FALSE)
cat2(y)

# Single line formatting
z <- dput2(x)
cat2(z)

Run the code above in your browser using DataLab