Difference between R MarkDown and R NoteBook

后端 未结 8 1756
时光说笑
时光说笑 2021-01-29 20:01

I am trying to understand at a high level what the differences between R Markdown and R NoteBook. I know they are interrelated but I would like to figu

8条回答
  •  自闭症患者
    2021-01-29 20:50

    One of the most important differences is not completely clear from the above answers.

    From Section 3.2.1.3 of the Bookdown book:

    There is also a Restart R and Run All Chunks item in the Run menu on the editor toolbar, which gives you a fresh R session prior to running all the chunks. This is similar to the Knit button, which launches a separate R session to compile the document.

    In other words, knitting creates a new environment and runs all the code there. By way of contrast, the R Notebook uses the Global Environment as is to render the HTML file. In fact, for an R Notebook, changes to the HTML file happen every time the .Rmd document is saved. The Preview button merely opens the HTML file in its current state. No code is run. Preview literally means what it says: it just shows you what has already been done.

    Why does this matter? For example, if an R Notebook .Rmd file is opened, but no code chunks are run, then the HTML file will render all the markdown and input code just fine, but no output will appear. Or, suppose you define some variable x in the Console, but not in a code chunk. If you try to use x somewhere in an R Notebook, it will work just fine. Previewing the HTML document will also work just fine. On the other hand, knitting the document will generate an "unknown variable" error because knitting runs all the code in a new environment, and the variable x was never defined in the markdown file anywhere.

提交回复
热议问题