Skip to content

Commit 42945bd

Browse files
use option and warning if package is not installed
1 parent e4b6067 commit 42945bd

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ importFrom(purrr,pmap)
3131
importFrom(purrr,pwalk)
3232
importFrom(purrr,reduce)
3333
importFrom(purrr,when)
34+
importFrom(rlang,is_installed)
3435
importFrom(rlang,seq2)
3536
importFrom(utils,tail)
3637
importFrom(utils,write.table)

R/vertical.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ construct_vertical <- function(x) {
1616
#' @param colored Whether or not the output should be colored with
1717
#' `prettycode::highlight()`.
1818
#' @param style Passed to `prettycode::highlight()`.
19+
#' @importFrom rlang is_installed
1920
#' @export
2021
print.vertical <- function(x, ...,
21-
colored = TRUE,
22+
colored = getOption("styler.colored_print.vertical"),
2223
style = prettycode::default_style()) {
2324
if (colored) {
24-
x <- prettycode::highlight(x, style = style)
25+
if (is_installed("prettycode")) {
26+
x <- prettycode::highlight(x, style = style)
27+
} else {
28+
warn(c(
29+
"Could not use colored = TRUE, as the package prettycode is not",
30+
"installed. Please install it if you want to see colored output."
31+
))
32+
}
2533
}
2634
cat(x, sep = "\n")
2735
}

R/zzz.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
.onLoad <- function(libname, pkgname) {
22
backports::import(pkgname, "trimws")
3+
op <- options()
4+
op.styler <- list(
5+
styler.colored_print.vertical = TRUE
6+
)
7+
toset <- !(names(op.styler) %in% names(op))
8+
if(any(toset)) options(op.styler[toset])
9+
invisible()
310
}
11+

0 commit comments

Comments
 (0)