Saturday, December 21, 2013

1.5 Saving and loading an R session

Saving the R session

If you want to continue that session in R at another moment, you can save the current session.
  1. Enter the command save.image('*location where you want to save*/*name of the session*.Rdata').
  2. It is recommended to save the file in the folder that is assigned as the working directory of the session, you can use the command getwd(). For this you could copy the path that leads you to the current working directory.
  3. Behind the last slash (/) of the location you could enter the name you want to choose for this session. Behind the name you need to put the extentions .Rdata. The example in Figure 12 shows that the session is saved by the name Sessie1.Rdata. The example also shows that the file of the session is saved in the folder Data, which is the folder that is used as working directory in this session.
  4. If you entered the command with location and file name, like in Figure 12, you can press enter to save the session.
  5. Closing the R console by clicking x of the window (of shutting of in another way), a dialogue window with the text Save workspace image? appears. Always choose yes to be sure the session is saved.
Figure 12: Saving the R session
Figure 12: Saving the R session

Loading a previous R session

There are two ways to load an exsisting or saved R session.
  • Looking in Windows Explorere (or Finder in Mac OS) to the .Rdata file and opening it by a double click.
  • First opening the R console and entering the command load('*location where the session is saved*/*name of the file*'), and pressing enter after this command.
By entering the command ls() you could show an overview of the variables (saved in the previous session) that are used in this R session.
Figure 13 shows that Bloemenverkoop (Flowersales) is the only variable that is created for a data set in this session.

Figure 13: Loading a previous R session
Figure 13: Loading a previous R session

No comments:

Post a Comment