Capture print() output as a character string.

printString(x, ..., max = getOption("max.print", 100L))

Arguments

x

An object used to select a print() method.

...

Passthrough arguments to print().

max

integer(1). Maximum length of vector. Works internally by calling head() on the print capture, prior to collapse using paste(). Supports getOption("max.print") global variable.

Value

character(1).

Details

Useful for returning informative messages inside a function.

Note

Updated 2019-07-29.

See also

Examples

printString(c("hello", "world"))
#> [1] "[1] \"hello\" \"world\""
printString(datasets::mtcars, max = 2L)
#> [1] " mpg cyl disp hp drat wt qsec vs am gear carb\nMazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4"