From 455624197f0a0918096ce3e22084ac268ab10de3 Mon Sep 17 00:00:00 2001 From: philchalmers Date: Fri, 6 Sep 2024 14:50:42 -0400 Subject: [PATCH] include previous connection saftey --- R/Eqn.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/Eqn.R b/R/Eqn.R index f5ec92f6..25aab6ae 100644 --- a/R/Eqn.R +++ b/R/Eqn.R @@ -120,13 +120,23 @@ Eqn <- function(..., html_output = knitr::is_html_output(), quarto = getOption('quartoEqn'), mat_args = list()) { + + # for connection saftey + sink.reset <- function(){ + if(sink.number() > 1L){ + for(i in seq_len(sink.number())){ + sink(NULL) + } + } + } + on.exit(sink.reset()) preview <- preview && interactive() if(preview){ quarto <- FALSE tmpfile <- tempfile() # everything except the kitchen ... sink(tmpfile) - on.exit(file.remove(tmpfile)) + on.exit(file.remove(tmpfile), add = TRUE) cat( " ---