Skip to content

Instantly share code, notes, and snippets.

@tonyelhabr
Last active October 10, 2019 12:12
Show Gist options
  • Save tonyelhabr/9bc3ae77aba4b2cd19bbc88c5c17babb to your computer and use it in GitHub Desktop.
Save tonyelhabr/9bc3ae77aba4b2cd19bbc88c5c17babb to your computer and use it in GitHub Desktop.
R functions for displaying information, warnings, and errors.
.verbose <- TRUE
.display_info <- function(x, ..., .envir = parent.frame(), verbose = .verbose) {
if(!verbose) {
return(invisible(NULL))
}
# usethis::ui_line(glue::glue('{x}'), .envir = .envir)
# Reference: `usethis::ui_line()`
x <- glue::glue_collapse(x, '\n')
x <- glue::glue(x, .envir = .envir)
cli::cat_line(x)
}
# NOTE: Ignore `verbose` for these.
.display_warning <- function(x, ..., .envir = parent.frame(), verbose = .verbose) {
usethis::ui_warn(x, .envir = .envir)
}
.display_error <- function(x, ..., .envir = parent.frame(), verbose = .verbose) {
usethis::ui_stop(x, .envir = .envir)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment