Data analysis with ProjectTemplate in RStudio with Git

January 17, 2016

(This article was first published on data prone - R, and kindly contributed to R-bloggers)


ProjectTemplate is a system for organizing and automating data analysis in R. Here is a recipe for creating a new ProjectTemplate project in RStudio and initializing version control with Git.

Order of Operations

I find that the following sequence is most efficient and error-proof:

  1. Create ProjectTemplate project
  2. Create RStudio project from directory created in Step 1
  3. Create a new Git repo at GitHub (or some other git hosting service)
  4. At command line, initialize git repo, add files, commit, and push to remote host
  5. Restart RStudio

Create ProjectTemplate project

At the console in RStudio, type


This will create the folder letters in your working directory with the ProjectTemplate file
structure. The create.project() command also changes your working directory to this new
ProjectTemplate project directory.

Create RStudio project

Select New Project... from the File menu in RStudio. In the New Project dialogue, select
Existing Directory:

Screenshot of RStudio Create Project dialogue

Browse to the newly created directory (letters in the example) and click Create Project.
A new sesson of RStudio will open and the new project will be loaded. (Note that the Git pane
within RStudio will not be available until after the final step.)

Create a new repo at Github

Create a new repo at Github. In the current example, it would be named “letters.” Do not add
any files (such as a README, .gitignore, or license) to the repo when creating it.

Initialize git repo and push to remote host

At the command line inside the project directory, type the following commands to initialize the
git repo, add the newly created template files, make your first commit, and push the commit to
the remote host. (Note that you will need to fill in your username and replace the repo name.)

git init
git add .
git commit -m "initialize project"
git remote add origin [email protected]:username/letters.git
git push -u origin master

Restart RStudio

The final step is to restart RStudio. The Git pane will appear automatically, and a .gitignore
file will be added to your project. (I generally add the cache directory to .gitignore.)

To leave a comment for the author, please follow the link and comment on their blog: data prone - R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)