I’ve recently been trying out Jupyter Notebook to organize my work. I had been holding out against using Jupyter or its predecessor Ipython becuase I was under the impression that it was only for Python users, but after taking a closer look it seems that you can also use other languages with it if you install the appropriate “kernels”. I now have it on both my work computer (running Linux) and my laptop (running Mac OS X) and it was relatively painless in both cases to get everything running, because the installation can be handled from a package manager. I’ve been using it with R, and the kernel for Jupyter is simply a package that you install from within R, though you have to remember to install the package when running R from a terminal window and not in RStudio.
One problem I encountered with an R notebook in Jupyter, though, was saving my workspace. In a normal R session I’m used to saving my workspace at the end of the session and coming back to it later to pick up where I left off. However, with the Jupyter notebook I found that I had to rerun all the code to regenerate all the objects again! This appears to be an issue for Python notebook users too.
There’s a very simple fix for this: Just run the standard R command
Your workspace will then be saved to the usual hidden .RData file in the same folder as the Jupyter notebook. If you want to share the code and the workspace, you’ll have to make sure that you copy both the notebook file and the .RData file that goes along with it.
Likewise, if you start a notebook in a folder that already has an .RData file, you’ll find that you can access that workspace from the Jupyter notebook – just run ls() to see what’s there.
I wonder if I may have missed a ‘save workspace’ function that’s already built in, though…