Image Credit: Ashwin Malshé

Using Rstudio Projects

In this post I will show how to create an Rstudio project and manage it. My main reason for working in such projects is that I am able to manage all my code and content from one single folder on the computer. I also use here package to manage links in the code.

For this tutorial you will need RStudio installed on your computer. The operating system doesn’t matter. I am using my MacBook Pro to record the videos.

Step 1: Install here package

Just run the following code in your Rstudio console:

install.packages('here')

Step 2: Create a project

Once you have successfully installed here, watch the following video to create your first RStudio project. Folder and files management is extremely important for professional analytics work. Therefore, think a little bit about the right place to create the project before you create your folder and save files. For this demo I am creating my project on the Desktop.


Creating Rstudio Project from Ashwin Malshe on Vimeo.


At the end of the video, I used here::here() to show me the path to the project directory. The path is /Users/ashwin/Desktop/Temp_Proj.

Step 3: Create subdirectories

This is not necessarily a required step but I prefer to create subdirectories depending on the type of content. For example, I create a subdirectory called Data to store all the data files. If my project uses images, I also create a subdirectory called Images. You can access all these using here package as follows. This is demo code and isn’t actually executed.

# The data file saved in a filder called `Data` inside the project folder
# The data file has extention .RDS

myData <- readRDS(here::here('Data', 'myDemoData.RDS'))

In the above code, I am accessing myDemoData.RDS inside Data subdirectory. here package already knows the path to the project folder. It simply appends each argument inside the here() function to the full path. Thus, the path to the dataset will be /Users/ashwin/Desktop/Temp_Proj/Data/myDemoData.RDS.

What is the benefit of using here package?

Dr. Jenny Bryan has done a fantastic job of explaining why you need here package! I don’t have to go beyond that. Please read her post on GitHub: https://github.com/jennybc/here_here

Related

comments powered by Disqus