Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save the object data to a file.
R Programming
saveRDS(data, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the file name in quotes.
Using a wrong file extension like .txt.
✗ Incorrect
The
saveRDS function requires the file name as a string, so it must be in quotes.2fill in blank
mediumComplete the code to read the saved RDS file into the variable loaded_data.
R Programming
loaded_data <- [1]("datafile.rds")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
load which is for .RData files, not .rds.Using
read.csv which is for CSV files.✗ Incorrect
The
readRDS function reads an RDS file and returns the saved object.3fill in blank
hardFix the error in the code to correctly save the variable my_list to a file.
R Programming
saveRDS([1], "mylist.rds")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name without underscore.
Putting the variable name in quotes.
✗ Incorrect
The variable name is
my_list, so it must be used exactly without quotes.4fill in blank
hardFill both blanks to save df to a file and then read it back into df_copy.
R Programming
saveRDS([1], [2]) df_copy <- readRDS("dataframe.rds")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the object and file name.
Not using quotes around the file name.
✗ Incorrect
You save the object
df to the file named "dataframe.rds" before reading it back.5fill in blank
hardFill all three blanks to save results to a file, read it back into loaded_results, and check if they are identical.
R Programming
saveRDS([1], [2]) loaded_results <- [3]("results.rds") identical(results, loaded_results)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
load instead of readRDS.Not using quotes around the file name.
✗ Incorrect
You save
results to "results.rds", then read it back with readRDS to compare.