From 104d457f99a220b1f2b7c567caa7102e42e4dd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Wed, 15 Jan 2025 11:40:59 +0100 Subject: [PATCH 1/2] Add initial hook --- inst/report/pkg_template.qmd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/inst/report/pkg_template.qmd b/inst/report/pkg_template.qmd index 387c821..3495acc 100644 --- a/inst/report/pkg_template.qmd +++ b/inst/report/pkg_template.qmd @@ -30,6 +30,18 @@ knitr::opts_chunk$set( cache = FALSE ) library("tools") +# Adapted from https://stackoverflow.com/a/52327256 +library("knitr") +knit_hooks$set(showDetails = function(before, options, envir, summary) { + if (before) { + str <- "
\n" + paste0(str, "", summary,"\n") + return() + } else { + return("\n
") + } +}) + ``` # Context From dda85f7dcaee65f43e8726dfaea62e24a1f94d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Mon, 27 Jan 2025 11:56:02 +0100 Subject: [PATCH 2/2] Improve hooks --- inst/report/pkg_template.qmd | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/inst/report/pkg_template.qmd b/inst/report/pkg_template.qmd index 3495acc..aecf2af 100644 --- a/inst/report/pkg_template.qmd +++ b/inst/report/pkg_template.qmd @@ -32,14 +32,12 @@ knitr::opts_chunk$set( library("tools") # Adapted from https://stackoverflow.com/a/52327256 library("knitr") -knit_hooks$set(showDetails = function(before, options, envir, summary) { - if (before) { - str <- "
\n" - paste0(str, "", summary,"\n") - return() - } else { - return("\n
") - } +hook_old <- knitr::knit_hooks$get("output") +knit_hooks$set(output = function(x, options) { + if (!is.null(options$summary)){ + x <- paste0("

", options$summary,"
", hook_old(x, options), "
") + } + x }) ``` @@ -108,7 +106,7 @@ unlist(.Platform) R's capabilities: -```{r capabilities} +```{r capabilities, summary = "Capabilities details"} capabilities() ```