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 (184 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:
|README.md||The intro file is used to provide project orientation. The file defines project objectives and is intended to introduce project data, source code and configurations for repeatable research. The *.md file format is that of a basic text or markdown file. When saved to GitHub, it will be used to create an HTML project wiki.|
|TODO.txt||A note file on a project’s development or implementation status with a list of bugs and future improvement needs.|
|.Rprofile||A hidden file in every project structure with instructions that are run at project start-up. The start-up file sources project configuration scripts and attaches data as needed.|
|cache||The cache is used to store data output.|
|config||Configuration settings are stored in one or more configuration scripts. The scripts are customized for each project.|
|data||The data directory stores all data inputs in raw format.|
|docs||Here you can store any source or reference material about the project.|
|image||Used to store image output, including Rplots, image files or gif animations.|
|lib||Used to store custom functions. The scripts provide useful functionality, but do not constitute analysis or production scripts per se|
|report||Used to store output tables and reports. R is capable of supporting a broad range of outputs including Word, Powerpoint, pdf, LaTeX and HTML.|
|src||Stores all project source code for analysis and repeatable research. The filename format #_name helps code sequencing and parallel processing.|
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.