1 R Projects
If you will be using R in your data project, you should start by creating an R Project in RStudio. This will create a new folder on your computer that will be the main project directory.
It will also create an .Rproj
file, which will tell R that all of the scripts and data files should be referenced from within your project folder. This is similar to setting a working directory with setwd()
except it is done automatically and R will use the “relative path” to all your files. This means that we can move the folder to a different location or to an entirely different computer all of your R scripts will still know where your files are located!
To create a new R Project, open RStudio and click File > New Project. Then select “New Directory”. This will prompt you to name your project, which will be the name of your main project folder, and where you want to save on your computer. You can also tell are to initialize git at this step if you plan on using version control in the project.
Once you have created a new R Project a good next step is to create subfolders for specific files, scripts, and outputs. The next section has some examples for creating a well-organized folder structure. Be sure to do this before you start writing your R scripts, it is much easier to start with a good structure in the beginning than to reorganized later on!
To open an existing R project, open RStudio and click File > Open Project or Open Project in New Session if you don’t want to close your current RStudio session. Alternatively, if you go to your project folder and double-click on the .Rproj
file then RStudio will launch a new session.
More details about using R Projects will be covered in the R training lesson materials.