aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2023-01-09 06:22:04 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2023-01-09 06:22:04 +0100
commit24eb77216700cf8b2f2bde3abad84c1f83f9e32a (patch)
tree1fecd5557499ea0e5d9a651f3a27fc602c0431cc /R
parenta5903e74d9cf54c764d5bbc48e461cecd5f56e72 (diff)
Prebuilt PDF vignettes, summary_listing
Diffstat (limited to 'R')
-rw-r--r--R/hierarchical_kinetics.R2
-rw-r--r--R/summary_listing.R59
-rw-r--r--R/tex_listing.R32
3 files changed, 60 insertions, 33 deletions
diff --git a/R/hierarchical_kinetics.R b/R/hierarchical_kinetics.R
index a90dd619..e545754a 100644
--- a/R/hierarchical_kinetics.R
+++ b/R/hierarchical_kinetics.R
@@ -13,7 +13,7 @@
#'
#' \dontrun{
#' library(rmarkdown)
-#' draft("New analysis.rmd", template = "hierarchical_kinetics", package = "mkin")
+#' draft("example_analysis.rmd", template = "hierarchical_kinetics", package = "mkin")
#' }
#'
#' @export
diff --git a/R/summary_listing.R b/R/summary_listing.R
new file mode 100644
index 00000000..38b52240
--- /dev/null
+++ b/R/summary_listing.R
@@ -0,0 +1,59 @@
+#' Display the output of a summary function according to the output format
+#'
+#' This function is intended for use in a R markdown code chunk with the chunk
+#' option `results = "asis"`.
+#'
+#' @param object The object for which the summary is to be listed
+#' @param caption An optional caption
+#' @param label An optional label, ignored in html output
+#' @param clearpage Should a new page be started after the listing? Ignored in html output
+#' @export
+summary_listing <- function(object, caption = NULL, label = NULL,
+ clearpage = TRUE) {
+ if (knitr::is_latex_output()) {
+ tex_listing(object = object, caption = caption, label = label,
+ clearpage = clearpage)
+ }
+ if (knitr::is_html_output()) {
+ html_listing(object = object, caption = caption)
+ }
+}
+
+#' @rdname summary_listing
+#' @export
+tex_listing <- function(object, caption = NULL, label = NULL,
+ clearpage = TRUE) {
+ cat("\n")
+ cat("\\begin{listing}", "\n")
+ if (!is.null(caption)) {
+ cat("\\caption{", caption, "}", "\n", sep = "")
+ }
+ if (!is.null(label)) {
+ cat("\\caption{", label, "}", "\n", sep = "")
+ }
+ cat("\\begin{snugshade}", "\n")
+ cat("\\scriptsize", "\n")
+ cat("\\begin{verbatim}", "\n")
+ cat(capture.output(suppressWarnings(summary(object))), sep = "\n")
+ cat("\n")
+ cat("\\end{verbatim}", "\n")
+ cat("\\end{snugshade}", "\n")
+ cat("\\end{listing}", "\n")
+ if (clearpage) {
+ cat("\\clearpage", "\n")
+ }
+}
+
+#' @rdname summary_listing
+#' @export
+html_listing <- function(object, caption = NULL) {
+ cat("\n")
+ if (!is.null(caption)) {
+ cat("<caption>", caption, "</caption>", "\n", sep = "")
+ }
+ cat("<pre><code>\n")
+ cat(capture.output(suppressWarnings(summary(object))), sep = "\n")
+ cat("\n")
+ cat("</pre></code>\n")
+}
+
diff --git a/R/tex_listing.R b/R/tex_listing.R
deleted file mode 100644
index 05f662e4..00000000
--- a/R/tex_listing.R
+++ /dev/null
@@ -1,32 +0,0 @@
-#' Wrap the output of a summary function in tex listing environment
-#'
-#' This function can be used in a R markdown code chunk with the chunk
-#' option `results = "asis"`.
-#'
-#' @param object The object for which the summary is to be listed
-#' @param caption An optional caption
-#' @param label An optional label
-#' @param clearpage Should a new page be started after the listing?
-#' @export
-tex_listing <- function(object, caption = NULL, label = NULL,
- clearpage = TRUE) {
- cat("\n")
- cat("\\begin{listing}", "\n")
- if (!is.null(caption)) {
- cat("\\caption{", caption, "}", "\n", sep = "")
- }
- if (!is.null(label)) {
- cat("\\caption{", label, "}", "\n", sep = "")
- }
- cat("\\begin{snugshade}", "\n")
- cat("\\scriptsize", "\n")
- cat("\\begin{verbatim}", "\n")
- cat(capture.output(suppressWarnings(summary(object))), sep = "\n")
- cat("\n")
- cat("\\end{verbatim}", "\n")
- cat("\\end{snugshade}", "\n")
- cat("\\end{listing}", "\n")
- if (clearpage) {
- cat("\\clearpage", "\n")
- }
-}

Contact - Imprint