R04: Reproducibility, File Organization, and Projects

Nicky Wakim

2024-10-09

Where are we?

Using OneDrive

  • We all have free access to OneDrive to store files

  • Let’s login into our online accounts

  • You can also download OneDrive for your desktop

    • Allows you to access the OneDrive from your computer’s interface instead of the browser

    • Creates a link between your computer and the cloud!

  • Let me show you mine

    • I can access all the files through RStudio as well!
  • Let’s take a couple minutes to log into OneDrive

05:00

Folder organization

  • Make a folder for our class!

    • I suggest naming it something like EPI_525_F24 to indicate the class and the term
  • Make these folders in your computer

    • Only make them in OneDrive if you have a desktop connection
  • For a project, I have the following folders

    • Background
    • Code
    • Data_Raw
    • Data_Processed
    • Dissemination
    • Reports
    • Meetings
  • For our class, I suggest making one folder for the course with the following folders in it:

    • Data
    • Homework
    • Lessons
    • R_activities
    • And other folders if you want
  • Take a few minutes to create these folders
05:00

Aside: folder and file naming

There are a few good practices for naming files and folders for easy tracking:

  1. Keep the name short and relevant
  2. Use leading numbers to help organize sequential items
    • I can show you my lessons folders as an example
  3. Use dates in the format “YYYY-MM-DD” so that files are in chronological order
  4. You can label different versions if you would like to
  5. Use “_” to separate sections of the name
    • I also use this to separate words, but some people say you should use “-” to separate words

Let’s go into R_activities

  • Make a folder called something like R04_work

  • We are going to stay in the R_activities folder

  • Now that we have some folders in order, we can start creating a project

Creating project in RStudio

  • Way to designate a working directory: basically your home base when working in R

    • We have to tell R exactly where we are in our folders and where to find other things

    • A project makes it easier to tell R where we are

  • Basic steps to create a project

    • Go into RStudio

    • Create new project for this class (under File or top right corner)

      • I would chose “Existing Directory” since we have already set up our folders
      • Make the new project in the EPI_525_F24 folder
  • Once we have projects, we can open one and R will automatically know that its location is the start of our working directory

The nice thing about R projects

  • 5 minute video explaining some of the nice features of R projects

https://rfortherestofus.com/2022/10/rstudio-projects

Reproducibility

  • Research data and code can reach the same results regardless of who is running the code

    • This can also refer to future or past you!
  • We want to set up our work so the entire folder can be moved around and work in its new location

Nicky’s process for R projects

  • Let me show you my process

    • I will create one in my Sample_folder

    • I will show you how I switch between classes

  • Make a project file in your class folder!

05:00

If time, we will move to R05: Intro to Quarto!