Another option is to save your data frame as a csv file. The benefit of this option is that it provides long term storage, i.e. you will (likely) be able to open your csv file on any platform in ten years time. With an RData
file, you can only open it with R and I wouldn't like to bet money on opening it between versions.
To save the file as a csv, just use: read.csv
and write.csv
, so:
write.csv(df, file="out.csv", row.name=FALSE)
df = read.csv("out.csv", header=TRUE)
Gavin's comment below raised a couple of points:
The CSV route only works for tabular-style data.
Completely correct. But if you are saving a data frame (as the OP is), then your data is in tabular form.
With R you'll always have the
ability to fire up an old version to read the data and export if for
some reason they change save format and don't allow the old format to
be loaded by another function.
To play devil's adovacate, you could use this argument with Excel and save your data as an xls
. However, saving your data in a csv format means we never need to worry about this.
R's file format is documented so one could reasonably easily
read the binary data in another system using that open info.
I completely agree - although "easily" is a bit strong. This is why saving as an RData file isn't such a big deal. But if you are saving tabular data, why not use a csv file?
For the record, there are some reasons for saving tabular data as an RData file. For example, the speed in reading/writing the file or file size.