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

Viewed 311

When I send or receive an R notebook, or even an R Project (from RStudio), the R notebook doesn't maintain any of the outputs; neither printed text or graphics show up, and the whole notebook has to be re-run to show the outputs. Is there some kind of setting I can turn on to make sure the outputs are embedded in the R Notebook so that I can send the notebook to someone else, like with Jupyter notebooks?

1 Answers

As per the official RStudio community blog here (and my own experience with RStudio), this is not possible.

The RStudio blog's Sustainer however brought up two good points (although it does not solve your problem):

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.

EDIT: if you are not tied up to RStudio, you can use JupyterLab instead (a powerful extension of Jupyter Notebooks - from the same project team). JupyterLab is language(kernel)-agnostic and does run nicely with R. All your work, included outputs, can then be fully saved - as you are familiar with in the Python world.

I used a cloud-based version of R JupyterLab hosted on GCP (Google Cloud Platform) but I am sure it can be deployed on your preferred environment as well (open source project, flexible, well supported by the Community).

Reference here

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

Related