为什么 R Notebooks save/embed 不在文件或 R 项目中输出?

Why don't R Notebooks save/embed outputs in the file or R Project?

当我发送或接收 R 笔记本,甚至是 R 项目(来自 RStudio)时,R 笔记本不保留任何输出;打印的文本或图形均未显示,整个笔记本必须重新运行 显示输出。是否有某种设置可以打开以确保输出嵌入到 R 笔记本中,以便我可以将笔记本发送给其他人,就像使用 Jupyter 笔记本一样?

根据官方 RStudio 社区博客 here(以及我自己使用 RStudio 的经验),这是不可能的。

然而,RStudio 博客的 Sustainer 提出了两个好点(尽管它没有解决您的问题):

If the purpose is to create a reproducible example, the reprex package is the way to go. This is great for short bits of r code and output.

You should also check our rmarkdown notebooks. Note that even with R's file >> save feature, you won't save plots etc. With rmarkdown or rmarkdown notebooks, you can intermix markdown formatted text, code, and code output (including tables and plots). You then also may knit that into html or pdf documents.

编辑:如果您不依赖于 RStudio,则可以改用 JupyterLab(Jupyter Notebooks 的强大扩展 - 来自同一项目团队)。 JupyterLab 与语言(内核)无关,并且 运行 可以很好地与 R 搭配使用。然后可以完全保存您的所有工作,包括输出 - 正如您在 Python 世界中所熟悉的那样。

我使用了托管在 GCP(Google 云平台)上的 cloud-based 版本的 R JupyterLab,但我相信它也可以部署在您喜欢的环境中(开源项目,灵活,得到社区的大力支持)。

引用here

Kernel-backed documents enable code in any text file (Markdown, Python, R, LaTeX, etc.) to be run interactively in any Jupyter kernel.