fit_screen: Nicely fits a message in the current R console

View source: R/misc_funs.R

fit_screenR 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 = 0.9, leading_ws = TRUE)

Arguments

msg

Text message: character vector.

width

The maximum width of the screen the message should take. Default is 0.9.

leading_ws

Logical, default is TRUE. Whether to keep the leading white spaces when the line is cut.

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 90% 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))

# The


dreamerr documentation built on Aug. 24, 2023, 1:08 a.m.