rr-markdown

How do you make output from help function display in Rmarkdown document


I have a very simple Rmarkdown document and I'm using the help function to get an overview if a dataset. When I knit the document, instead of displaying the results of the help call in the resulting HTML document a new browser page is opened with the results of the help call.

How do I get the help information to display in the knitted html file?

Here is the simple rmarkdown:

---
title: "Help not working"
author: "Stackoverflow"
date: "8/31/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(fpp2)
```

#### gold

```{r}
help(gold)
```

Solution

  • I don't think there is an very obvious way to do this - try this one (similar to what Waldi suggested):

    Would be interesting if there is a more elegant solution.

    ---
    title: "Help not working"
    author: "Stackoverflow"
    date: "8/31/2020"
    output: html_document
    ---
    
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    library(fpp2)
    library(forecast)
    ```
    
    # Example helpfile
    
    ```{r, echo = F}
    helpfile <- utils:::.getHelpFile(help(gold))
    outfile <- tempfile(fileext = ".html")
    tools:::Rd2HTML(helpfile, out =outfile)
    rawHTML <- paste(readLines(outfile), collapse="\n")
    knitr::asis_output(htmltools::htmlPreserve(rawHTML))
    ```