Chapter 3 RStudio Project
3.1 Objectives
At the end of the chapter, we hope readers will be able
- to link their RStudio with our datasets. The datasets are on our GitHub repository.
- to create an RStudio Cloud project using our GitHub repository
- to create an RStudio project on a local machine using our GitHub repository
3.2 Introduction
In this chapter, we will guide you to have a similar folder and file structure to our project for this book. This folder and file structure will help you run the codes with minimal error risk. Furthermore, to achieve this, we will use the RStudio Project.
On the RStudio Project webpage, it says that RStudio projects make it straightforward to divide your work into multiple contexts, each with their working directory, workspace, history, and source documents.RStudio projects are associated with R working directories. You can create an RStudio project:
- on RStudio Cloud or RStudio on your local machine
- In a brand new directory
- In an existing directory where you already have R code and data
- By cloning a version control (Git or Subversion) repository
3.3 Dataset repository on GitHub
We will use the our GitHub repository that contains the book’s datasets. The name of the repository is data-for-RMed
. To go to the repository, click on this link
3.4 RStudio project on RStudio Cloud
Now, we will create a RStudio Cloud project based on the our GitHub repository. Go to your RStudio Cloud login page
Next, log in to RStudio Cloud using your credentials
Once inside your work space, click New Project:
Now, click on New Project from Git Repository
:
Once you have done that, you will need to go back to our data-for-RMed
repository on GitHub. And then you need to click on Clone
and click the copy button for HTTPS
:
Next, we will clone the repository on our RStudio Cloud. This will ensure the file structure is the same with that of on the RStudio Cloud. Following that, just click OK:
What you will see on your screen is a a new Rstudio Cloud project. It will read Your Workspace
and the directory name is data-for-RMed
3.5 RStudio project on local machine
The steps are rather similar if you want to create a new project on your local machine using the same GitHub repository. What you need to do is first, start your the RStudio IDE:
On the menu, click File
, then click New Project
:
Then, next you need to click Project
and then click Version Control
:
After that, you click Git
:
As you remember from the previous step where we copied GitHub HTTPS. So it is the same step here. Copy the HTTPS link from dataset-for-RMed
GitHub repository:
Now, you can paste the HTTPS link (see the Figure). You will notice that the Project directory name
will be automatically filled. You can next click on Browse
, so that you can choose whichever folder that you prefer to be your working directory. We recommend you using your home directory (such as Documents
if your are using Microsoft Windows OS).
And now you will notice that RStudio will create a new working directory on your local machine. This working directory contains the same folder and file structures with the our GitHub repository:
3.6 Summary
In this chapter, we want readers to have the same folder and file structure with us. This will minimize errors during analysis. The datasets sit on the book GitHub repository. Then, we provide the instructions to create new RStudio projects on RStudio Cloud and on RStudio IDE on the local machine by using the our GitHub repository HTTPS link.