Skip to content

Commit

Permalink
use option and warning if package is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert committed Aug 21, 2018
1 parent e4b6067 commit 42945bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ importFrom(purrr,pmap)
importFrom(purrr,pwalk)
importFrom(purrr,reduce)
importFrom(purrr,when)
importFrom(rlang,is_installed)
importFrom(rlang,seq2)
importFrom(utils,tail)
importFrom(utils,write.table)
12 changes: 10 additions & 2 deletions R/vertical.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ construct_vertical <- function(x) {
#' @param colored Whether or not the output should be colored with
#' `prettycode::highlight()`.
#' @param style Passed to `prettycode::highlight()`.
#' @importFrom rlang is_installed
#' @export
print.vertical <- function(x, ...,
colored = TRUE,
colored = getOption("styler.colored_print.vertical"),
style = prettycode::default_style()) {
if (colored) {
x <- prettycode::highlight(x, style = style)
if (is_installed("prettycode")) {
x <- prettycode::highlight(x, style = style)
} else {
warn(c(
"Could not use colored = TRUE, as the package prettycode is not",
"installed. Please install it if you want to see colored output."
))
}
}
cat(x, sep = "\n")
}
8 changes: 8 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.onLoad <- function(libname, pkgname) {
backports::import(pkgname, "trimws")
op <- options()
op.styler <- list(
styler.colored_print.vertical = TRUE
)
toset <- !(names(op.styler) %in% names(op))
if(any(toset)) options(op.styler[toset])
invisible()
}

0 comments on commit 42945bd

Please sign in to comment.