user_display {catchr}R Documentation

Display conditions in output terminal


These functions make a catchr plan immediately print the condition to the output terminal, similar to how display works. But unlike display and most catchr functions or special reserved terms, these functions are meant to be used in user-defined functions of a plan.

user_display() immediately displays a condition n the output terminal, and if crayon is installed, will style the text with whatever crayon styling is supplied (either as a crayon function or a character vector for crayon::combine_styles()). This function should be used within a custom function, i.e., function(x) {user_display(x, "pink")}, and not called by itself, since when it is called, it doesn't evaluate to a function, string or unquoted term, which are required input types to a catchr plan.

display_with can be used at the "top" level of a plan, since it returns a function that calls user_display(). Thus user_display("pink") is equivalent to the example above.


user_display(cond, crayon_style, ...)

display_with(crayon_style, ...)



A condition one wishes to display


If crayon is installed, this can be either a crayon style (e.g., crayon::green(), blue$bold, etc.) or a character vector for crayon::combine_styles(). These styles will be applied to the output.


Parameters to pass into extract_display_string(); namely cond_name (which controls how the condition is introduced) and include_call, which determines whether the call is included.

See Also

the display special term, which essentially uses a version of user_display; user_exit() and exit_with() for parallel functions for the exit special term, and beep_with() for a parallel function for the beep special term.


make_warnings <- function() {
  warning("This warning has a call")
  warning("This warning does not", call. = FALSE)

# The crayon stylings won't work if `crayon` isn't installed.
catch_expr(make_warnings(), warning = c(display_with("pink"), muffle))
           warning = c(display_with(c("pink","bold"), include_call = FALSE), muffle))
catch_expr(make_warnings(), warning = c(display_with("inverse", cond_name=NULL), muffle))
# If you don't want to use crayon styles, just use `NULL`
catch_expr(make_warnings(), warning = c(display_with(NULL, cond_name="Warning"), muffle))

# You can get a lot of weird crayon styles
if (requireNamespace("crayon", quietly = TRUE) == TRUE) {
  freaky_colors <- crayon::strikethrough$yellow$bgBlue$bold$blurred
             warning = c(function(x) user_display(x, freaky_colors), muffle))

[Package catchr version 0.2.31 Index]