Understand the importance of reproducible workflows and version control
Learn how to set up a project in RStudio
Explore version control with GitHub and GitHub Desktop
Fork, edit, and publish a GitHub repository
Why reproducible workflows are important
Its good science
Improves uptake of methods
Ease of collaborations
Funders love Open Science
What makes a workflow reproducible?
Works on any machine
Yields identical results every time
Can be understood by externals (and future self)
Workspace Hygiene
Start from a clean slate!
Your workspace is your laboratory - keep it free of contamination!
Tools > Global Options > General
In the “Basic” tab
Unceck “Restore .RData into workspace at startup”
Set “Save workspace to .RData on exit” to “Never”
Workspace Hygiene
Absolute and Relative Paths
Your code should run on any machine!
# BAD PRACTICE: path and data does not exist on other machinesread.csv("C:/path/to/important/raw/data.csv")
# BAD PRACTICE: works only on one specific machinesetwd("C:/path/to/folder/that/only/exists/on/my/machine")
# BAD PRACTICE: requires manual work# to run this script, go to# Session -> Set Working Directory -> To Source File Location# to set your working directory correctly
Introducing: RProjects
Project files that set working directory automatically after opening the project
Whole project folder can be passed between machines and people
You can easily make your own copy of a repository by “forking” it
Cloning your new repository
Now we’re going to “clone” this repo to our local machine using GitHub Desktop. You can also do this in RStudio, but we will use GitHub Desktop for this example.
Making a new R project
Now let’s make a new R project based on this cloned repository…
Git in RStudio
Making and committing changes
Now let’s make some changes to the repository:
Open the README.md file in RStudio and add some text to it. Perhaps your name or today’s date. Make sure to save the file.
You’ll now see that the README.md file has been modified in the Git panel in RStudio.
Click the checkbox next to the README.md file in the Git panel to stage the changes.
In the “Commit message” box, write a brief description of the changes you made (e.g., “Added my name to README”).
Click the “Commit” button to commit the changes to your local repository.
Click the “Push” button in the Git panel to upload your changes to GitHub.
Advanced GitHub
Some other topics that you can explore on your own:
Branching and Merging: Manage changes to your codebase with branches and merge them back into the main branch
GitHub Issues: Track bugs and feature requests (yes, this applies to research code!)
Pull Requests: Propose changes to a repository and collaborate with others