Save and Load RData Workspace Files in R

16 Dec, 2021
In this article, we will discuss how to save and load R data workspace files in R programming language.
The save.image method in R is used to save the current workspace files. It is an extended version of the save method in R which is used to create a list of all the declared data objects and save them into the workspace. These files can then later be read into the corresponding saved data objects using the load() method. 
Syntax:
save.image(file = “.RData”)
Arguments : 
file – name of the file where the R object is saved to or read from.
Example: Saving R data workspace files
R
# creating data objectsobj1 <- c(1:5)         obj2 <- FALSE                      obj3 <- "Geeksforgeeks!!"   # saving all data to the pathsave.image("saveworkspace.RData")
 These files can be loaded into the workspace using load() function.
Syntax: 
Load(path)
Example: Loading R data workspace files 
R
# loading the workspaceload("saveworkspace.RData")
 Output: 
The saveRDS and readRDS methods available in base R are basically used to provide a means to save a single R object to a connection, mostly a type of file object, and then to restore the object. The restored object may belong to a different name. This approach is different from the save and load approach, which saves and restores one or more named objects into an environment. It is used to save a single object into the workspace. 
Syntax:
saveRDS(object, file = “”)
Arguments : 
object – R object to serialize.
file – name of the file where the R object is saved to or read from.
Syntax: 
readRDS(file)
Example: Saving and loading R data workspace  
R
# creating data objectsobj1 <- c(1:5)         obj2 <- FALSE                      obj3 <- "Geeksforgeeks!!"   # saving all data to the pathsaveRDS(obj1, file = "saveworkspaceobj1.RData")print("Data object1") # loading the workspacereadRDS("saveworkspaceobj1.RData")
 Output: 
[1] "Data object1" 
[1] 1 2 3 4 5
The save method in R writes an external representation of R objects to the specified file. These R objects can be retrieved back from the workspace using the load method.  
Syntax:
save(objects, file)
Arguments :
objects- The list of the objects to be saved
file – the file name for the R objects to be saved and read from
Example: Saving and loading R data workspace 
R
# creating data objectsobj1 <- c(1:5)         obj2 <- FALSE                      obj3 <- "Geeksforgeeks!!"   # saving all data to the pathsave(obj1, obj3, file ="tempworkspaceobj.RData") load("tempworkspaceobj.RData")
 The RData objects are stored at the specified paths shown in the below snapshot.
Output:  
 
anikakapoor
Picked
R-FileHandling
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Split Column Into Multiple Columns in R DataFrame?
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
How to filter R DataFrame by values in a column?
R - if statement
Logistic Regression in R Programming
Replace Specific Characters in String in R
How to import an Excel File into R ?
Joining of Dataframes in R Programming