Skip to content
R for the Rest of Us Logo

An Important Workflow Tip

If the video is not playing correctly, you can watch it in a new window

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Learn More

Jenny Bryan and Jim Hester have written about why it’s best practice to not restore .RData at startup as part of their What They Forgot to Teach You About R workshop. See, in particular, Chapter 1 of their materials, where they write:

Saving code – not workspaces – is incredibly important because it is an absolute requirement for reproducibility. Renouncing .Rdata and restarting R often are not intrinsically important or morally superior behaviours. They are important because they provide constant pressure for you to do the right thing: save the source code needed to create all important artefacts of your analysis.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Marisel Strand

Marisel Strand

March 11, 2024

Thank you for such a great class!:)

David Keyes

David Keyes Founder

March 11, 2024

Glad you liked it!

Rachel Udow

Rachel Udow

March 31, 2024

All the content about Quarto has been extremely helpful -- and it's also made me realize that I have been using R Markdown differently than intended. For example, I generally do all of my coding in R Markdown files because I like the visual separation between the text and code chunks -- but I never render it, and I use text to convey information that should probably be reflected as #comments instead.

Going forward, I'd like to update existing script that I'll continue to use repeatedly in the future to align with the process David described at the very end of this lesson. This would involve transferring code that is currently contained in code chunks in an R Markdown file into an R script file. My question is -- is there a way to do this "globally" for an R Markdown file, or would I need to go through and copy/paste the contents of each code chunk from R Markdown to R script? Thanks!

Libby Heeren

Libby Heeren Coach

March 31, 2024

Hey, Rachel! You can use the purl function to turn a .Rmd file into a .R file. You can find an example of how to do that here in the Rmarkdown Cookbook: https://bookdown.org/yihui/rmarkdown-cookbook/purl.html

Dalton Bailey

Dalton Bailey

April 9, 2024

Is there an easy way to still save a workspace even after changing this stuff? Here is an example I actually ran into at work where I would want to save objects.

I was doing some geocoding, where I was sending addresses to geocoding APIs and getting back lat-long coordinates, and then saving that information as a new object. The issue is that the geocoding services I was using only allow a certain number of API calls for free daily (and I really don't want to pay for it!). So, at the end of the R session I would save the workspace to avoid a situation where I would have to continue to call the API and go over my limit every time I reran that code.

Is there a better option than saving the workspace at the end of a session?

David Keyes

David Keyes Founder

April 9, 2024

Yes! You'll learn in the Going Deeper course how I do this. Basically, I do all of my data cleaning and then save the clean data frames as RDS files (this an R format for saving data). Then, when I want to do reporting in a Quarto document, I just import the clean RDS files. This works especially well for geocoding because a) it takes a while and b) you avoid going over API limits. Hope that helps!

Dalton Bailey

Dalton Bailey

April 10, 2024

Very helpful, I am looking forward to learning about it!

Thank you very much for this course, David! I am reviewing my current workflow and thinking of performing tasks in R using everything I learned here going forward.

David Keyes

David Keyes Founder

April 10, 2024

Glad you found it useful!