Creating Projects

Purpose of This Tutorial

The purpose of this tutorial is to illustrate the reason to create projects when using R and RStudio. We will walk through why projects are useful, how to create projects and how to open projects.

Why Create a Project?

RStudio projects make it make it much easier to share your full folder of work. It allows you to not worry about setting a permanent working directory location that may not be available as you move from one workstation to another. A project allows you to have a working directory that is relative to the location of your projecte, allowing you anyone to open up your project and begin working without having to worry about setting the correct working directory.

If you do not create a project in R and you want to reference, for example, a csv file, you would have to set the working directory that points to that file. This can often be a rather long string of characters such as read.csv( "C/Users/David/Desktop/R_Analysis/Data/david_test.csv"). If you create a project in the “R_Analysis” folder, you would only have to type read.csv("Data/david_test.csv)“, much easier. Also, The earlier version would not work if I sent my Analysis/R code to a colleague. However, a project would work perfectly fine if I sent it to a colleague.

Creating an R Project

There are two main ways (one more exists we can discuss another time) to create a project in R. One of them is to simply create a project within an already existing folder/location. The other way is to create a brand new folder/location from within RStudio that will hold the project.

The first step in creating a new project is to go to File -> New Project.

Within the next window, you will have three choices: To create a new directory, use an existing directory, or use version control.

In this tutorial we will focus on the top two choices.

Create Project from an already Existing Directory/Folder

Oftentimes when you are working in R you are not starting from scratch. Usually you will have data already located in a folder somewhere or some notes/documents that already exist. If this is the case, than it is a good idea to create your project file (.Rproj) within that folder. This will automatically point R to this folder whenever doing input/output. To do this, all you need to do is click on “Existing Directory” and then point to the folder that you want to use as a project folder.

Ensure that you click on the folder and not into the folder. You want the .Rproj file to be at the top level of your folder. Once done, click into your folder outside of RStudio and make sure that you see a .Rproj file.

Create Project in a New Directory/Folder

In those cases where you have not already created a folder, you can use R to create a folder and a project file all at the same time. To do this, click on New Directory.

In the next window you will have a bunch of choices. We will focus only on creating a new project here, however, keep these other choices in mind for more advanced projects that you might be working on.

From the next window, you simply need to tell RStudio where you want to create this new folder/project.

Version Control

You can also clone a GitHub repository, but I will talk about that process in a different tutorial.

Opening an Already Created Project

After creating a project (.Rproj) file, you can access your newly created project by going into the folder where you created the folder and double clicking on the proper .Rproj file.

Or, opening RStudio, going to File -> Open Project and navigating to your project folder and selecting the .Rproj file.

To check that your project was created appropriately, look in the bottom-right hand side (if using default settings) of the screen at the files tab. This should contain the file(s) that are in your project folder.