Skip to content
R for the Rest of Us Logo

Managing Project Files for Reproducibility

This lesson is locked

Get access to all lessons in this course.

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

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

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

What is the advantage of using "here" instead of just typing the subfolder name in the path? Isn't it hard-coded either way so it would be the same amount of work to update if the files got moved around or folders got renamed?

As in, why in this example is it preferable to put: globalData2019 <- read_spss(here("globaldata","Pew Research Center Global Attitudes Spring 2019 Dataset WEB.sav"))

instead of: globalData2019 <- read_spss("globaldata/Pew Research Center Global Attitudes Spring 2019 Dataset WEB.sav")

?

David Keyes

David Keyes Founder

October 20, 2023

Please see Jenine's answer below. In addition, this article by Malcolm Barrett gives some idea about why you might want to use here even when working in an RStudio project.

I will also say that I tend to use it when working in projects with both Quarto/RMarkdown documents and R script files. That's because the working directory of Quarto/RMarkdown documents is wherever they are located while for R script files it is the root of the project. The here package can help ensure that code works identically in either type of file.

Jenine Harris

Jenine Harris

October 20, 2023

The here package helps to avoid problems with working directories when collaborating. If your collaborator has the working directory manually set (or defaulted) to somewhere other than the top folder of the project, the second version you posted would not work for them. In many cases, the second will work just fine and is less typing, for sure, but then you'll get one collaborator with a stubborn installation or a habit of using setwd() at the start of their workflow and there will be trouble. Using R Project files also helps to avoid problems with working directories. Here is a nice description of this issue: https://www.tidyverse.org/blog/2017/12/workflow-vs-script/

At the very least, you'll avoid Jenny Bryan setting your computer on fire.

Thanks for the great question!