fit_screen {dreamerr} | R Documentation |
Nicely fits a message in the current R console
Description
Utility to display long messages with nice formatting. This function cuts the message to fit the current screen width of the R console. Words are never cut in the middle.
Usage
fit_screen(msg, width = NULL, leading_ws = TRUE, leader = "")
Arguments
msg |
Text message: character vector. |
width |
A number between 0 and 1, or an integer. The maximum width of the screen the message should take.
Numbers between 0 and 1 represent a fraction of the screen. You can also refer to the
screen width with the special variable |
leading_ws |
Logical, default is |
leader |
Character scalar, default is the empty string. If provided, this value will be placed in front of every line. |
Details
This function does not handle tabulations.
Value
It returns a single character vector with line breaks at the appropriate width.
Examples
# A long message of two lines with a few leading spaces
msg = enumerate_items(state.name, nmax = Inf)
msg = paste0(" ", gsub("Michigan, ", "\n", msg))
# by default the message takes 95% of the screen
cat(fit_screen(msg))
# Now we reduce it to 50%
cat(fit_screen(msg, 0.5))
# we add leading_ws = FALSE to avoid the continuation of leading WS
cat(fit_screen(msg, 0.5, FALSE))
# We add "#> " in front of each line
cat(fit_screen(msg, 0.5, leader = "#> "))