Saving and loading data in R

Saving and loading data in R

Last edit: mapar3 (13 Dec 2016 14:33) | Revisions: 2 | Created by: mapar3 | Rating: 0

This short page will help you get started with R. In particular, it will help you load and save your R scripts using the functions:

  • save()
  • load()

So, imagine you have now a short code that you have been working on (a reproducible example)

A<-matrix(c(1,2,3,4,5,6), nrow=3, ncol=2)

Now you get tired and want to continue another day. Then in order to save it you use the function save()

save(A,B,C, file="matrices.RData"))

Note that the second part of the function is the specification of the file name. This will save the 3 elements we selected (A,B,C) in a file called matrices, that can be loaded some other time again in R.

An alternative would be using save.image(), which saves the whole working space.


In both cases the documents are saved in the directory you set for working at the beginning (with setwd() function)

You can safely close your R and whenever you want to continue working then you will use the function load()


Then you will have loaded all your elements again.

Hope this was useful and good luck starting with R.1

rating: 0+x
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License