Save & load
Save and load R data
Save and load data in .RData or .rds file format
( see → read & write for saving data as text files )
- to save one or several variables (including their variable names)
- to save the pure data content of a single variable (without keeping the variable name)
Save multiple variables
# save multiple variables (objects)
# load data into new R environment "ev" to avoid overwriting variables having the same name
# load data (without new environment): overwrites all variables in R that have the same name
Save all variables
# save all variables (data objects) from the current R working session
# load the saved R variables (same as above)
# list all variables present in R
Save data content of a single variable (RDS)
While load() by default re-loads the variables into the global R environment (and potentially overwriting identical variable names, if not protected by defining a new environment), readRDS() can be used to better control individual variable names of imported data.
Use saveRDS to save a single variable and to re-load the content into any new variable name.
# save content of variable "x"
# load data (of former variable "x") into a new variable "a"
Get list of saved R data files
# list all .RData files in current directory (path=".")