SSCC - Social Science Computing Cooperative Supporting Statistical Analysis for Research

1.4 RStudio projects

A project in RStudio is a collection of work organized in a folder. RStudio provides tools that will help you manage your work on projects. Some of the many tools are,

  • RStudio remembers what files you had open and what tabs were displayed, when you close a project. When you open the project again, RStudio will open the same files and display the same tabs. This will allow you to quickly pick up your work again. A new R session is started when you open a project, so some previously executed commands may need to be run again.

  • Additional debugging tools, such as setting break points.

  • Integrated source control. This is an important part of reproducible code.

  • Integration of code results with documents.

Almost any R work can be structured as a project. You might consider creating a project for an individual class, your thesis, or a research project. While RStudio can work with individual files which are not in a project, you will likely find it quicker to develop R code using projects.

1.4.1 Creating a project

RStudio can create new projects using three different methods, New Directory, Existing Directory, or Version Control. All three of these method can be useful. New users to R will likely want to use the New Directory method to get started. As your R knowledge and skills increase the other methods may be useful. To create a new project, select New Project from the file drop down menu.

The file menu of Rstudio

Figure 1.5: The file menu of Rstudio

The New Project window will allow you to select which method of project creation you want.

The file menu of Rstudio

Figure 1.6: The file menu of Rstudio

  • The New Directory option is used when a new project is being started. This will create a .Rproj file. If you have git installed, you can also start source control for the project.

    You will have the option to create an Empty Project or an R Package. Packages are written by experienced R programmers. R Packages allow you to share finished R code with others users.

    The Empty Project is what most new R users will use.

    The file menu of Rstudio

    Figure 1.7: The file menu of Rstudio

  • The Existing Directory option is used to create a project in a directory which already contains R programs. This will create the RStudio project (the .Rproj file), but does not set up source control for this project.

  • The Version Control option is used to start a local project folder from an existing project, provided the existing project is using Git. This is often a project which is shared by researchers.

1.4.2 Opening a project

An existing project can be opened by double clicking on the .Rproj file from a file explorer. The .Rproj file will have a icon of a blue cube with the letter R inside of it.