View source: R/tableToString.R
tableToString | R Documentation |
Captures the printed output of a data.frame or an R object (coerced to a data.frame) as a single string with preserved formatting. Useful for error messages, logging, and string-based output.
tableToString(obj)
obj |
An R object that can be coerced to a data.frame |
A character string containing the formatted table output with newlines
# Basic usage with a data.frame
df <- data.frame(
numbers = 1:3,
letters = c("a", "b", "c")
)
str_output <- tableToString(df)
cat(str_output)
# Using in error messages
df <- data.frame(value = c(10, 20, 30))
if (any(df$value > 25)) {
msg <- sprintf(
"Values exceed threshold:\n%s",
tableToString(df)
)
message(msg)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.