12.3 What is the difference between a Notebook and an R Markdown file?
Most people use the terms R Notebook and R Markdown interchangeably and that is fine.
Technically, R Markdown is a file, whereas R Notebook is a way to work with R Markdown files.
R Notebooks do not have their own file format, they all use .Rmd
.
All R Notebooks can be ‘knitted’ to R Markdown outputs, and all R Markdown documents can be interfaced as a Notebook.
An important difference is in the execution of code.
In R Markdown, when the file is Knit
, all the elements (chunks) are also run.
Knit is to R Markdown what Source is to an R script (Source was introduced in Chapter 1, essentially it means ‘Run all lines’).
In a Notebook, when the file is rendered with the Preview
button, no code is re-run, only that which has already been run and is present in the document is included in the output.
Also, in the Notebook behind-the-scenes file (.nb
), all the code is always included.
Something to watch out for if your code contains sensitive information, such as a password (which it never should!).