1

I am working with a R notebook and it is very important to me that the final HTML page will show all the code and the outputs.

Right now, when I look at the preview, some chunks of code only show the last part of the code while I want it to show everything. I have partly solved with problem by creating chunks that look like this

```{r eval=FALSE} code ```

However, this does not show outputs on the final HTML file. Anyone knows how I can solve this problem? Thank you

  • 1
    Welcome to SO! Could you host your document and point to where the problem is? By default, the {r} tab would show all the code and outputs. 'eval=FALSE' means the code is not being evaluated while the document is created, which means the outputs are not being shown. – csgroen Apr 05 '18 at 13:51

2 Answers2

2

There is a difference, although subtle, between R Markdown, and R Notebooks, which are a type of document written in R Markdown. See this explanation from RStudio for more info. In particular:

Ordinary R Markdown documents are “knit”, but notebooks are “previewed”. While the notebook preview looks similar to a rendered R Markdown document, the notebook preview does not execute any of your R code chunks; it simply shows you a rendered copy of the markdown in your document along with the most recent chunk output.

This means that if you have large chunks for which you only run, say, the second half as you iterate on your code, likely because the first half does some object creation or reading in data and so doesn't need to be repeated, it will not show up when you "Preview". To guarantee that everything displays, you can either "Knit" your document (I wouldn't do this) or simply go to "Run" dropdown in the top right of the editor and select "Restart R and run all chunks."

Calum You
  • 14,687
  • 4
  • 23
  • 42
1

Only chunks that were run as whole chunks (like with the green play button) will show in the preview file. If you run them row by row- it won't show them.

Avish
  • 36
  • 5