Code works interactively but not while knitting

我与影子孤独终老i 提交于 2020-08-17 05:41:09

问题


I have an RMarkdown document with some R code in it. The code works fine when I'm running it interactively in the console. However, when I try to knit the document (using the "knit" button in RStudio), R throws error messages that some objects cannot be found.


回答1:


When you compile a document (using the "knit" button in RStudio), knitting takes place in a separate R session. Therefore, your document must be self-contained:

  1. Objects from the Global Environment of your interactive sessions are not available when knitting. You must create/load all objects from within your document.
  2. You must load all packages used from within your document.

Also note that while knitting, your working directory is changed to the directory containing your document (by default). Therefore, relative paths (for example, paths to data sets you want to read) might not point to the expected files.



来源:https://stackoverflow.com/questions/62563941/code-works-interactively-but-not-while-knitting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!