tl;dr
- Printed data frames in an HTML notebook created with RStudio's Preview button has pretty, interactive data frames
- Printed data frames in an HTML notebook created with
rmarkdown::render()
does not - Non-printed data frames look the same in both (i.e.
df
as opposed toprint(df)
reprex
Whitespace added so the ``` ticks could be displayed
- Create the following RMD file, save two copies.
---
title: "R Notebook"
output: html_notebook
---
```{r}
df <- data.frame(One = 1:26, Two = letters)
df
```
```{r}
print(df)
```
- Open one copy in RStudio. Run it, and click Preview. Open the resulting file in browser.
- Render the other copy with `rmarkdown::render("second-copy.Rmd", "html_notebook"). Open resulting file in browser.
- Compare the results.
- See that while the first tibble looks the same in both HTML documents, the second does not.
In full
When I run a Rmd notebook in RStudio, and then hit Preview, the resulting HTML document printed data frames are interactive (you can click through multiple pages) and pretty:
However, when I render the notebook with rmarkdown::render()
, I can't achieve the same result. Instead, data frames are presented in plaintext and without interactivity:
To render I have used
rmarkdown::render("file.Rmd", output_file = "file.nb.html")
rmarkdown::render("file.Rmd", "html_notebook")
rmarkdown::render("file.Rmd", output_file = "file.html")
rmarkdown::render("file.Rmd", "html_document")
I have found that the inconsistency is only with printed data frames (e.g. print(df)
). I've previously chosen to print all the data frames because a) I understand that is good practice and b), more crucially, when I don't, some of the desired data frames aren't printed.