Insert the following code to your .Rprofile file: options(renv.download.override = utils::download.file). Certify that renv is activated (renv::activate()). 2.1 (optional) Delete all packages, except for renv, installed in ./renv/library. Reinstall renv with its dependencies with utils::install.packages(“renv”, dependencies = TRUE). Restart R (.rs.restartR()). Try to install a package using renv::install() (e.g., renv::install(“dplyr”)). Also, don’t forget to read renv’s _ Alternative downloaders_ section: https://rstudio.github.io/renv/articles/package-install.html#alternative-downloaders .
How-To Guide: Setting Up a Quarto Project with renv on a New Computer (macOS & Windows)
This guide will walk you through the steps to get your Quarto project, complete with its isolated renv package environment, up and running on a fresh machine.
Prerequisites: What You Need to Install First
Before you touch your project, you need the core software installed.
- Install R
- Install RStudio (Highly Recommended)
- Download the RStudio Desktop (Free) version from RStudio.com. This is the easiest way to manage your project.
- This step is optional but highly recommended for a smoother experience.
- Install Quarto
- Quarto is a separate command-line tool. Download and run the installer from Quarto.org.
- Verification: Open your system’s terminal (macOS) or Command Prompt/PowerShell (Windows) and type
quarto check. This will confirm Quarto, R, and necessary packages are correctly detected.
- Install the
renvpackage (in R)Open RStudio (or just the R application).
Run this command in the R console:
install.packages("renv")
Step-by-Step: Restoring Your Project
Now that the basics are installed, it’s time to work on your specific project.
- Get Your Project Files
- Transfer your entire project folder (the one containing the
.Rproj,_quarto.yml,renv.lock, and.Rprofilefiles) to your new computer. You can use a USB drive, cloud storage (Dropbox, Google Drive), or version control (GitHub, GitLab).
- Transfer your entire project folder (the one containing the
- Open the Project
- The Easy Way (Using RStudio):
- Double-click the
.RProjfile in your project folder. This will automatically open RStudio and set the correct working directory. - RStudio will likely detect the
renvenvironment and show you a prompt asking if you want to activate it. Click “Yes”.
- Double-click the
- The Manual Way (Terminal/Command Prompt):
- Open your terminal (macOS) or Command Prompt (Windows).
- Navigate to your project directory using the
cdcommand. - Example for Windows:
cd C:\Users\YourName\Documents\My_Quarto_Project - Example for macOS:
cd ~/Documents/My_Quarto_Project
- The Easy Way (Using RStudio):
- Restore the Packages
With your project open in RStudio, the console should already be ready.
Run the following command to install all the packages exactly as they were in the original project (versions and all):
renv::restore()This will read the
renv.lockfile and start downloading and installing all the necessary packages from CRAN. This process can take a few minutes.
- What if the automatic activation didn’t happen?
If you’re not using RStudio or the prompt didn’t appear, you can manually activate and restore
renv.In your R console (within the project directory), run:
renv::activate() # Ensures the project uses its private library renv::restore() # Installs the packages
Testing and Final Steps
Render Your Project
From RStudio: Click the “Render” button in the script editor while any
.qmdfile is open.From the Terminal: Navigate to your project directory and run:
quarto render # or render a specific file quarto render my_report.qmdIf it renders successfully, congratulations! Your environment is set up correctly.
Troubleshooting Common Issues
- “Package not available” or download errors:
Check your internet connection.
Try specifying the CRAN repository in the restore command:
renv::restore(repos = "https://cloud.r-project.org")
- System Dependency Errors (e.g.,
sf,curl,V8):- Some R packages require software outside of R.
- macOS: The easiest fix is to install Homebrew, then run
brew install geos gdal. The error message will usually tell you what’s missing (libgit2,pandoc, etc.). - Windows: The
rtoolstoolchain that comes with R usually handles this. Ensure you selected “Install RTools” during the R installation. If a specific library is missing, you may need to download it manually (this is rarer on Windows for common packages).
- R Version Mismatch:
renvwill warn you if the current R version doesn’t match the one used to create thelockfile. You can often proceed anyway withrenv::restore(), but be aware of potential compatibility issues.
- “Package not available” or download errors:
Summary Checklist
You should now have a perfectly replicated development environment on your new machine!