Use R Project to Organize Your Scripts and Data

  1. Create a R Project using R Studio

  2. Create sub-folders inside your R project directory (either using R Studio or in Finder/Computer)

  3. Move your data file to the corresponding sub-folder outside of R studio

  4. Go back to R Studio (double click the R project). Create a new R markdown file and save it inside the corresponding sub-folder
    Example of a R project structure:
    Example of a R project structure

  5. load the libraries for importing data

library(rio)
library(here)
## here() starts at /Users/BerniceCheung/Dropbox (University of Oregon)/Teaching/psy611
  1. Use the here function to specify the location of the data file inside the import function. The here function always starts with the folder where your R project locates. Enter the name of the sub-folder (can be multiple lyers of sub-folders) to specify the location, then enter the file name.
df <- import(here('data', 'wave1', 'data.csv'))

Check more information about R project here

Common Error Messages

Couldn't find the file:

  1. check if your R project is open in R Studio (Always open your r script by double clicking the R project)

  2. check if the file is inside the sub-folder you specify in here.

  3. check the file name and the file extension name.