When you start working on projects in RStudio you’ll soon find that you have lots of different files. You might have your scripts with your analysis code, your data files, and even RMarkdown files. With all these files, you’ll need a way to keep them organised. RStudio provides a system for this called an Rstudio project.
In RStudio you organise your work in project files. Project files, have the extension
.Rproj and they live inside a particular folder.
You can think of the folder as being the project. That folder is going to store all the files (your document files, your data files etc) associated with the project. The project file will also be stored in that folder and the project file is there to tell RStudio that that particular folder contains a project and that it’s not just any ordinary folder.
To create a new project go to File > New Project
You’ll give the name of your project in the box labelled Directory name:. You can click on Browse… and navigate to where you want you project folder to be located, and then click on Create Project to actually create your project.
For undergraduates at Sussex, we enforce a particular organisation for their RStudio projects. However, you’re welcome to organise your own projects however you see fit. However, on good structure that I would recommend is a sub-folder called
data to store your data files, and a sub-folder called
r_docs to store your RMarkdown files, and maybe a folder called
scripts for you scripts and other code files. To create these subfolders just click on New Folder in the Files pane of RStudio1.
Organising your work in RStudio projects doesn’t change anything about how you save your work. Once you’ve created an RStudio project, you don’t need to save the project. You only ever need to save the individual files like your script file etc. In fact, you never need to touch the project file again.
Once you close RStudio done, you’ll probably want to continue your work at a later point. To do this, you can navigate to your project folder (using Finder or File Explporer) and click on your
.Rproj file to open that project in RStudio. Any files you then want to open can be opened through the Files pane (clicking on your
.Rproj file in the Files pane will just bring up your the Project Options settings). Making sure you always open your project first, and then use the Files pane to open specific files will allow you to get the maximum benefit from using a project. And we’ll discover some of these benefits when we start working with data files (and we’ll cover some additional benefits in the advanced R course)!
As a general rule, to make sure your RStudio projects play nicely with Windows, MacOS, and Linux, I recommend that folder and file names follow a couple of conventions. Specifically, names should be entirely lower case, and underscores (
_) should be used instead of spaces.↩︎