Skip to contents

Capture print() output as a character string.

Usage

printString(x, ..., max = getOption(x = "max.print", default = 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().

Value

character(1).

Details

Useful for returning informative messages inside a function.

Note

Updated 2023-01-30.

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"