R Projects and Files in a Project

First, watch the video, then read about the projects and R working directories. The video demonstrates one of the ways you can efficiently manage your files in a project. The discussed file structure will work in many cases but may need to be revised when large data are used and it is impossible or impractical to move the data to the local data folders. Also, the video assumes that each script file (for data loading, cleaning, plotting, etc.) is relatively large; hence it makes sense to keep the code separately so it is more manageable. Suppose each file (for data loading, cleaning, visualizing, and statistical analysis) contains just a few lines. In that case, it might be more practical to keep the codes together in a single script – you are free to decide based on the needs and size of your project.

Summary

In summary, RStudio projects give you a solid workflow that will serve you well in the future:

  • Create an RStudio project for each data analysis project.
  • Keep data files there; we'll talk about loading them into R in data import.
  • Keep scripts there; edit them, run them in bits or as a whole.
  • Save your outputs (plots and cleaned data) there.
  • Only ever use relative paths, not absolute paths.

Everything you need is in one place, and cleanly separated from all the other projects that you are working on.