A project template provides a common content structure for data analysis projects. A template can offer several benefits:
- Define a familiar workspace
- Enable collaboration
- Ensure consistency across machines and time.
The project template is simple in nature. It has everything a good project should have to achieve repeatable research and results.
Projects in RStudio
RStudio makes it easy to create a project. In particular, each project has its own working directory, source files, workspace settings and history.
There are 3 ways to create an RStudio project:
- In a brand new directory
- In an existing directory where you already have R code and data
- By cloning a version control archive (in Git or Subversion)
For example, use the CreateProject command to start a new project (available on the RStudio global toolbar):
RStudio takes several actions when a new project is created:
- First, it creates a project file with an .Rproj extension in the project directory. The file defines project options (discussed below);
- Next, a hidden directory named .Rproj.user is created to store temp files;
- Finally, the project loads into RStudio, displaying its name in the Projects toolbar.
The project structure of directories and files can be copied into place once a new a project Directory is created. For example, the image defines a base project template:
The file structure is easy to create. Download the template here:Project Template (334 downloads)
Is this the only template to use? Of course not. However, it is a good starting.
The role of each element in the project structure is clarified below. For example:
[table id=77 /]
There are several ways to open a project:
- First, use the OpenProject command to select an existing project file,
- Second, select a project from the list of most recently opened projects,
- Third, double-click on the *.Rproj file.
Meanwhile, RStudio takes several actions when a project it opened. For example:
- The R session (process) is started
- Commands launch from the .Rprofile file (if any);
- Old data loads from the .Rdata file (if allowed);
- History details open from the .Rhistory file;
- The project directory becomes the present working directory.
- Files open in the editor.
RStudio provides options to customize a project. Most important, the options can control the flow of data into memory. For instance:
- Restore .RData into workspace at startup: Loads the.RData file into R at startup. It can help t0 uncheck this item if project data is large;
- Save workspace to .RData on exit: Controls whether to save .RData on exit;
- Always save history: Sets if the .Rhistory file is always saved from your session.