Search code examples
rsaveenvironment

Save Environment "Data" and "Values" along with script in R


Title says it mostly. I want to be able to save all my data frames, vectors, variables, etc along with the code into a single file so that I dont have to reimport data and recreate the dfs, vectors, etc each time I open R. I have tried looking through the Global Options but havent found anything that works.


Solution

  • If you are using R studio, when you want to close the application, it asks you if you want to save image file. Select the image and save it. This will allow you to save the data frames and other values as well.

    enter image description here

    you can also clean data frames before saving the image, so you only keep values and data frames that are important for you. Attention: saving large data frames image will cause a delay in loading R every time you are going to open it.