An Introduction to ProjectTemplate

John Myles White, a Ph.D student in the Princeton psychology department, wrote an indispensable package for R, ProjectTemplate, which I use for managing both trivial and complex R projects. 

The ProjectTemplate package provides a function, create.project(), that automatically builds a directory for a new R project with a clean sub-directory structure and automatic data and library loading tools. The hope is that standardized data loading, automatic importing of best practice packages, integrated unit testing and useful nudges towards keeping a cleanly organized codebase will improve the quality of R coding.

The inspiration comes from the rails command from Ruby on Rails, which initializes a new Rails project with the proper skeletal structure automatically. Also, ProjectTemplate follows Rails's approach of preferring convention over configuration: the automatic data and library loading as well as the automatic testing work easily because assumptions are made about the directory structure and naming conventions used in your code. You can customize your codebase however you'd like, but you will have to edit the automation scripts to use your conventions instead of the defaults before you'll get their benefits again ...

I recommend using the version available through CRAN.

However, if you're comfortable building your own R packages, then I recommend using the latest version (0.2-1) which includes many noteworthy features, e.g. the addition of caching support and the replacement of an individual preprocessing file with a specified munge directory. You can find more information on the ProjectTemplate GitHub repository.

Installation

In R, use the install.packages() function:

install.packages('ProjectTemplate')

R might prompt you to select a mirror (e.g. FAS-IT Research Computing at Harvard University's).

Creating a Project

 In R, initialize ProjectTemplate by using the library() function:

library('ProjectTemplate')

Next, change your working directory to a directory where you have write-access (i.e. your "My Documents" folder). In R for Windows, select File > Change dir... Or, alternatively, use the setwd() function.

 Finally, create a new project using the create.project() function. For example, if I'm creating a project for MATH-25:

create.project('MATH-25')

ProjectTemplate will then build the MATH-25 directory in your working directory.

Opening a Project

First, copy your data (e.g. an Excel spreadsheet or CSV text file) into the data directory (e.g. /MATH-25/data/).

Next, in R, change your working directory to the MATH-25 directory by selecting File > Change dir... or using the setwd() function:

setwd('MATH-25')

Finally, open your project using the load.project() function:

load.project()

ProjectTemplate will then autoload and preprocess your data.

For more information and best practices I recommend reading the Overview, Default Project Layout, and Automatic Data Loading sections in the README or on the ProjectTemplate GitHub repository.