ETC5513: Collaborative and Reproducible Practices
Tutorial 10
Objectives
- Learn to use
renv
for dependency management - Collaborate with a partner to test reproducibility
- Practice using GitHub for version control
Pair Programming Setup
Pair up with a partner and decide who will be Person A and Person B.
Both partners should create a new repository on GitHub:
- Go to GitHub and log in.
- Click on the New Repository button.
- Give your repository a name (e.g.,
renv-tutorial
). - Check the boxes to include a license, a
.gitignore
file, and a README file. - Click Create Repository.
Clone your repository to your local machine:
- Copy the repository URL from GitHub.
- In RStudio, go to File > New Project > Version Control > Git.
- Paste the repository URL and choose a local folder to clone the repository.
Open the cloned repository in RStudio.
Inside your repository, create a new Quarto file:
- Go to File > New File > Quarto Document.
- Save the file as
analysis.qmd
.
Initializing renv
Initialize
renv
in your R session not inside the Quarto document:::init() renv
- This will create a local library for your project and generate
renv
files.
- This will create a local library for your project and generate
Stage, commit, and push the changes to GitHub:
git add . git commit -m "Initialize renv" git push origin main
Data Analysis Tasks
Person A: Palmer Penguins
Install the
palmerpenguins
package:install.packages("palmerpenguins")
Use the
penguins
dataset to:- Create a summary table of the data.
- Generate a plot (e.g., scatterplot of flipper length vs. body mass).
Make sure you add the library command to your Quarto document
Add cross-references to the plot in your Quarto document.
Snapshot the project dependencies in the R console:
::snapshot() renv
Stage, commit, and push your changes to GitHub.
Person B: Life Tables
Install the
HistData
package:install.packages("HistData")
Use the
Breslau
dataset, filtered toage >= 5
, to:- Create a summary table of the data.
- Generate a plot (e.g., Age at death against number of deaths).
Add cross-references to the plot in your Quarto document.
Snapshot the project dependencies:
::snapshot() renv
Stage, commit, and push your changes to GitHub.
Testing Reproducibility
Share your repository details with your partner.
Clone each other’s repository and open it in RStudio.
Restore the project dependencies:
::restore() renv
You should see
renv
installing the necessary dependencies for the project.Check your library paths with
.libPaths()
. Do you recognise the path?Render the Quarto document. Verify that you can reproduce the analysis and outputs.
Discuss any issues encountered and how to resolve them.
Extension: Try adding a development package from GitHub (e.g., naniar
) and follow the renv
workflow. Verify if the package is recorded in the lockfile and how it differs from CRAN packages.