From a1e812e1fcb6b158fd73ca101cdf2b3a1a1101e3 Mon Sep 17 00:00:00 2001 From: Miles McBain Date: Thu, 3 Mar 2022 22:18:02 +1000 Subject: [PATCH] make check pass and use global env for buffer --- DESCRIPTION | 2 +- R/output.R | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 01f801f..7774cf9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/R/output.R b/R/output.R index a1f08fa..401e390 100644 --- a/R/output.R +++ b/R/output.R @@ -1,8 +1,11 @@ -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(...) @@ -10,19 +13,19 @@ output <- function(...) { } 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() { @@ -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(...) } \ No newline at end of file