From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Use saveRDS() and readRDS() to serialize objects

Use saveRDS() and readRDS() to serialize objects

From the course: R for Data Science: Lunch Break Lessons

Use saveRDS() and readRDS() to serialize objects

- [Instructor] If you're doing frequent calculations on large data sets it's handy to save out objects versus saving out source code. And saveRDS and readRDS are two functions to help you with that. In order to demonstrate I need a vector, so I'll create a vector called, no, how about myvector, and into it I'm going to place, oh, I don't know, one through five, it doesn't matter. Now we have an object called myvector. Let's use saveRDS, S-A-V-E-R-D-S, and then I name the item that I'm saving. And then I name where I want to save it to, so the file equals sample_saveRDS, and you can call it whatever you'd like. And when I hit Return it saves myvector out into the file called sample_saveRDS. Let's go ahead and remove myvector, and you'll notice that the global environment on the right-hand side is now empty. Let's bring it back. I can go readRDS, I tell it the filename of the sample that I want to bring back in.…

Contents