Skip to content

Commit

Permalink
make check pass and use global env for buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesMcBain committed Mar 3, 2022
1 parent 9445b91 commit a1e812e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: paint
Title: paint data.frames summaries in colour
Version: 0.1.3
Version: 0.1.4
Authors@R:
person(given = "Miles",
family = "McBain",
Expand Down
21 changes: 12 additions & 9 deletions R/output.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
OUTPUT_TO_BUFFER <- FALSE
OUTPUT_BUFFER <- NULL
utils::globalVariables("PAINT_BUFFER")
PAINT_BUFFER <- new.env()

PAINT_BUFFER$OUTPUT_TO_BUFFER <- FALSE
PAINT_BUFFER$OUTPUT_BUFFER <- NULL

output <- function(...) {
if (!OUTPUT_TO_BUFFER) {
if (!PAINT_BUFFER$OUTPUT_TO_BUFFER) {
cat(..., sep = "")
} else {
append_to_output_buffer(...)
}
}

append_to_output_buffer <- function(...) {
OUTPUT_BUFFER <<-
PAINT_BUFFER$OUTPUT_BUFFER <-
c(
OUTPUT_BUFFER,
PAINT_BUFFER$OUTPUT_BUFFER,
unlist(list(...))
)
}

reset_output_buffer <- function() {
OUTPUT_BUFFER <<- NULL
PAINT_BUFFER$OUTPUT_BUFFER <- NULL
}

get_output_buffer <- function() {
OUTPUT_BUFFER
PAINT_BUFFER$OUTPUT_BUFFER
}

get_output_buffer_rows <- function() {
Expand All @@ -40,7 +43,7 @@ get_output_buffer_rows <- function() {
}

paint_to_output_buffer <- function(...) {
OUTPUT_TO_BUFFER <<- TRUE
on.exit(OUTPUT_TO_BUFFER <<- FALSE)
PAINT_BUFFER$OUTPUT_TO_BUFFER <- TRUE
on.exit(PAINT_BUFFER$OUTPUT_TO_BUFFER <- FALSE)
paint(...)
}

0 comments on commit a1e812e

Please sign in to comment.