aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-11-01 20:32:54 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-11-01 20:32:54 +0100
commit65bb1c5587801444a6b47a344b285ec5ca06c048 (patch)
tree8c339c46dfe323afc952311757275324a61eeec3 /R
parentb53ca24f26c759a8ecf5e00f791a4134dd1a926c (diff)
Add tex_listing()
Diffstat (limited to 'R')
-rw-r--r--R/tex_listing.R32
1 files changed, 32 insertions, 0 deletions
diff --git a/R/tex_listing.R b/R/tex_listing.R
new file mode 100644
index 00000000..05f662e4
--- /dev/null
+++ b/R/tex_listing.R
@@ -0,0 +1,32 @@
+#' 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