fit_screen | R Documentation |
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.
fit_screen(msg, width = NULL, leading_ws = TRUE, leader = "")
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. |
This function does not handle tabulations.
It returns a single character vector with line breaks at the appropriate width.
# 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 = "#> "))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.