Starting Projects in RStudio

Being oRganized Beginner Reproducibility

Let’s learn to start projects in RStudio - an important step to a good workflow in R.

Soundarya Soundararajan true
08-04-2021

Why projects?

I created n number of files while I started working with R at the beginning. I worked on multiple projects all of which accumulated in the same folder. I learnt about a good workflow only later and I believe it is important to be organized from the beginning of learning R.

Enter an important step in reproducible research: Working within projects. Learning to work within projects even at the beginning lets you be organized by maintaining the analyses files in a legible way. This prevents you from drowning into n^n files you would otherwise accumulate. Also, this makes your analyses reproducible and hence makes this a crucial step to Open Science workflow.

How to start a project?

Prerequisite

First, create a folder in your system where you would store all the R projects. Remember exactly where create this.

Step - 1a

Open R studio, and go to

File –> New project

Click New Project

Step - 1b

Another way of opening a new project is clicking on the current project you are working on when RStudio is open. You can find what project you are currently working at the right top corner of the environment pane.

Click on the current project folder

You can create new project from here as well.

Click new project

Step - 2

Either way (step 1a/1b) opens the following window

Pop-up window for creating new project

Step - 3

Click new directory and select new project.

Note what other things can be done other than creating a project

Step - 4

Give a name related to your data analysis as a new project name and remember to select the folder you created in step 1 from the browse button under create project as a subdirectory of.

Give a name to the project This creates the new project you just created inside the R project folder you created at the prerequisite step.

Libraries to create project folders and subfolders

I will brief on two other ways you can create projects and related folders; these come in handy when you don’t know how to organize but you need to be.

library(ProjectTemplate)

library(ProjectTemplate)
#create.project(project.name = "trial project") 

I have added a comment tag (# symbol) here to avoid creating a project folder in this library, I only want to demonstrate, not create, hence the tag, you might want to drop the # symbol to create the folder. Also you can name the project whatever you want.

A project folder “trial project” is created
Click and expand the folder to view the contents
All folders have a README file
Read the README files to know what and where you can store your analyses and files
There you go!

library(starter)

While writing this I came across another package, library(starter) which helps you create project subfolders. Here you would use create_project(), note the underscore between create and project, unlike create.project() in ProjectTemplate library.

For more information on this package read here.

Take Home

So, create an R project for every data analysis you work on. Maintain your analysis scripts, data and also the plots here at one place. When reviewer 2 asks for any additional analyses, be confident and pull the files in style.

“consumer confidence!” by Frederick Homes for Sale is licensed with CC BY-SA 2.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/2.0/

Happy organizing until I see you tomorrow with another post!

Citation

For attribution, please cite this work as

Soundararajan (2021, Aug. 4). My R Space: Starting Projects in RStudio. Retrieved from https://github.com/soundarya24/SoundBlog/posts/2021-08-03-starting-projects-in-rstudio/

BibTeX citation

@misc{soundararajan2021starting,
  author = {Soundararajan, Soundarya},
  title = {My R Space: Starting Projects in RStudio},
  url = {https://github.com/soundarya24/SoundBlog/posts/2021-08-03-starting-projects-in-rstudio/},
  year = {2021}
}