4

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)
```
Mutuelinvestor
  • 3,384
  • 10
  • 44
  • 75
  • 4
    does this help : https://www.r-bloggers.com/printing-r-help-files-in-the-console-or-in-knitr-documents/ – Waldi Aug 31 '20 at 20:45
  • @Waldi Thanks for this. My only issue is that the html output is actual raw html source code it is not rendered. Is it possible to render the output. – Mutuelinvestor Aug 31 '20 at 22:10

1 Answers1

4

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))
```         
Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
  • This worked nicely. Is it possible to decrease the font? – Mutuelinvestor Aug 31 '20 at 22:05
  • Yes, this would be possible by adjusting rawHTML. Try to inspect what is in rawHTML - you will see this is the raw html text for the help file. You would need to add the specific additional html tags at the positions where you want your changes. – Steffen Moritz Aug 31 '20 at 22:12
  • You can also wrap the whole chunk with, e.g., ... . Note, that this will not necessarily look optimal, because it only affects font size of the help text, not the headers. – user3283722 Jul 28 '21 at 08:01
  • Great answer, thanks. Can't help but add that this should be easier. – jtr13 Jan 15 '23 at 19:38
  • @SteffenMoritz, et. al. Please refer to the comment by Yihui Xie on Sep 10, 2014 [https://stackoverflow.com/questions/24146843/including-r-help-in-knitr-output]. Use the `printr` package. – iembry Apr 12 '23 at 20:06