Explicitly Recording Packages
As with the previous exercise, it is recommended that you fork the repository to your GitHub account and clone it to your local machine to follow along with the examples. This will allow the course facilitators to see your work, provide feedback, and troubleshoot with you as needed.
If you’re not familiar with using git and GitHub, you can skip the forking and cloning steps and instead download a zip file of the repository.
Adding Packages to therenv.lock File
The exercises for initiating and snapshotting a project can be found in the explicit-record-exercises folder of the intro-to-renv-exercises repo.
Instructions
- Open the
explicit-record-exercises.Rprojproject. - Check the identified dependencies by running
renv::dependencies().- What packages are identified as direct dependencies and why?
- Initiate {renv} by running
renv::init(). - Double-check the status of the dependencies by running
renv::status().- Is the lock file in-sync with the project library? (Hint: it should be.)
- Open the
analysis_doc.qmdfile and try to Render the analysis document.- Why did the rendering fail?
- Check the documentation for the
map_data()function using?ggplot2::map_data. What package is still needed?
- Explicitly record the needed package with
renv::record("package_name"). - Check the status of the dependencies again by running
renv::status().- What has changed?
- Install the newly identified dependencies by running
renv::restore().- If you receive a message that looks like the one below, choose to “Activate the project and use the project library:”
> renv::restore() It looks like you've called renv::restore() in a project that hasn't been activated yet. How would you like to proceed? 1: Activate the project and use the project library. 2: Do not activate the project and use the current library paths. 3: Cancel and resolve the situation another way. - Open the
analysis_doc.qmdfile again, and Render the analysis document.- Was it successful this time? Why or why not?
- Why did you need to explicitly record one of the packages to be able to render the document?
- Take a look at the
DESCRIPTIONfile for {ggplot2} to help understand:packageDescription("ggplot2"). <!– 11. Runrenv::snapshot(), but typenand hit RETURN when prompted with “Do you want to process? (Y/n)?” We don’t actually want to complete this step, but we do want to look at the output. - What does the output indicate?
- Why does renv want to remove a package?
- Take a look at the
- Add –>
- Close the
explicit-record-exercises.Rprojproject.