From d511c275aa63f2318787b72a442da92861ca20d1 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 7 Dec 2024 12:06:34 -0500 Subject: [PATCH] Initial skeleton --- R/knitr_interaction.R | 16 ++++++++++++++++ inst/knitr_example.Rmd | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 R/knitr_interaction.R create mode 100644 inst/knitr_example.Rmd diff --git a/R/knitr_interaction.R b/R/knitr_interaction.R new file mode 100644 index 0000000..0160f50 --- /dev/null +++ b/R/knitr_interaction.R @@ -0,0 +1,16 @@ +# Store the default knitr source hook for when not using ggtibble +default_source_hook <- knitr::knit_hooks$get('source') + +knitr_hook_ggtibble <- function(x, options) { + +} + +knitr_option_ggtibble <- function(options) { + if (!is.null(options$ggtibble)) { + stopifnot(inherits(options$ggtibble, "ggtibble")) + + if (is.null(options$fig.cap)) { + options$fig.cap <- options$ggtibble$caption + } + } +} diff --git a/inst/knitr_example.Rmd b/inst/knitr_example.Rmd new file mode 100644 index 0000000..a75d847 --- /dev/null +++ b/inst/knitr_example.Rmd @@ -0,0 +1,23 @@ +--- +title: "Untitled" +output: pdf_document +date: "2024-07-31" +--- + +```{r setup, include=FALSE} +chunk_option_ggtibble <- function(options) { + if (isTRUE(options$ggtibble)) { + browser() + stop() + } +} + +knitr::opts_chunk$set(echo = TRUE) +knitr::opts_hooks$set(ggtibble = chunk_option_ggtibble) +``` + +```{r pressure, echo=FALSE, ggtibble = TRUE, fig.cap=d_plot$caption} +d_plot <- data.frame(A = 1) +d_plot$caption <- "foo" +plot(pressure) +```