Quantcast
Channel: why does kable not print when used within a function in rmarkdown - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by dww for why does kable not print when used within a function in rmarkdown

$
0
0

The problem seems to be related to knitr::kable incorrectly detecting the environment for the printing when it is embedded inside a function. This interferes with its ability to correctly figure out how to format. We can hack around this by placing the object to print in the top level environment before we print it.

---title: "Markdown example"output: html_document---```{r setup, include=FALSE}knitr::opts_chunk$set(echo = TRUE)print_kable = function(x) {  print(kable_print_output <<- x)  cat('\n')}```# Markdown example```{r mtcars, results='asis'}make_outputs <- function() {  print_kable(knitr::kable(head(mtcars)))  plot(mtcars$mpg, mtcars$cyl)  print_kable(knitr::kable(tail(mtcars)))  }make_outputs()```

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>