When using rmarkdown
to knit a document in RStudio, I want to use a particular function to print a data.frame
(in my case, pander
to get a multiline table). The rmarkdown
package documentation says that, in addition to the four valid methods that can be passed to df_print
, I can also pass it an arbitrary function:
In addition to the named methods you can also pass an arbitrary function to be used for printing data frames.
I want to set the df_print
option in the YAML header:
output:
pdf_document:
df_print: pander
However, when using the Knit button in RStudio, it errors, saying:
Error: Invalid value for df_print (valid values are default, kable, tibble, paged
Execution halted
But, when I call the render
function directly:
render("example.Rmd", pdf_document(df_print = pander))
The document renders just fine, and I get the PDF file I want. Is RStudio inserting itself into the knitting process when I use the Knit button in a way that it doesn't when I just call render
directly? Why can't I pass an arbitrary function in the YAML header as well?
I also tried passing pander::pander
, but that didn't help.
You can force the evaluation of an expression in the YAML header using !expr
:
output:
pdf_document:
df_print: !expr pander::pander
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With