0
0
R Programmingprogramming~5 mins

readRDS and saveRDS in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the saveRDS() function do in R?

saveRDS() saves a single R object to a file in a binary format. This file can later be loaded back into R with readRDS().

Click to reveal answer
beginner
How do you load an R object saved with saveRDS()?

You use the readRDS() function and provide the file path. It returns the saved object, which you can assign to a variable.

Click to reveal answer
intermediate
What is the difference between saveRDS()/readRDS() and save()/load() in R?

saveRDS() and readRDS() work with a single object and do not restore the object name automatically. save() and load() can save/load multiple objects and restore their names in the environment.

Click to reveal answer
beginner
Write a simple example to save a data frame df to a file called data.rds.
saveRDS(df, file = "data.rds")
Click to reveal answer
beginner
How do you assign the object loaded from data.rds to a variable my_data?
my_data <- readRDS("data.rds")
Click to reveal answer
Which function do you use to save a single R object to a file?
AreadRDS()
BsaveRDS()
Cload()
Dwrite.csv()
What does readRDS() return when you load a file?
AThe saved R object
BNothing, it just loads the object into the environment
CA list of all objects in the file
DA character string of the file name
Which statement is true about saveRDS() and save()?
A<code>saveRDS()</code> saves one object; <code>save()</code> can save multiple objects
B<code>saveRDS()</code> saves multiple objects; <code>save()</code> saves one object
CBoth save multiple objects
DNeither saves objects to files
If you use readRDS() to load an object, what must you do to use it?
AUse <code>load()</code> afterwards
BNothing, it loads automatically
CCall <code>attach()</code> on it
DAssign it to a variable
Which file extension is commonly used for files saved with saveRDS()?
A.txt
B.csv
C.rds
D.rdata
Explain how you would save an R object and then load it back later using saveRDS() and readRDS().
Think about saving first, then loading and assigning.
You got /3 concepts.
    Describe the main difference between saveRDS()/readRDS() and save()/load() in R.
    Consider how many objects each can save and how they restore names.
    You got /3 concepts.