Updated: Jul 18
When I first started using R, I really struggled to keep track of my scripts. Like many, I started by working directly in the R console. It makes it so hard to navigate, correct mistakes, and can be so frustrating that it almost made me stop learning. Discovering RStudio saved my data analysis career. It makes R feel more like a usable piece of software as opposed to only a programming language and it dramatically lessened my learning curve.
I have already written about how to download RStudio. In this article, I am going to talk briefly about some of the quick features of RStudio so that you can jumpstart your learning.
First, you need to understand how an R Project lives in RStudio. When you launch RStudio, the first thing you want to do is create a project. Projects allow you to have multiple files linked together under a single heading. It helps you organize your thoughts and your files. I highly recommend creating a generic project that you can play in without messing up your other work. I call mine “R Playground”. You should also create a new project for each thing you are working on. For example, I always create a new project for each client or research question. This helps me ensure that scripts and data and outcomes stay neatly separated.
Within each project you will have scripts. Scripts are the actual writing that you do to program R to calculate statistics. You can have multiple scripts nested under each project. For example, if I am working on using statistical methods to match school leaders with possible mentors, I may write several scripts that explore different matching models to ensure that I can get the best outcome.
When you are working in RStudio, you will conduct your work within a four-panel screen that works like a dashboard. In the top left corner you will find your script panel. This is where you will write all of the language to run your statistical tests. You can have multiple scripts open at once, and each one populates in a tab across the top. You can save each script using the save icon. You can also “Run” your script by line using the “Run” button in the script window.
Below your script box is the console box. Whenever you run a script, your output occurs here. You can also type directly into the console box, but be aware, every time you hit Enter you will run your new line of code. This is where you will type if you want to do quick things, like check the structure of a data set or download a new package from the CRAN. You can clear the console by clicking on the little broom.
On the right hand side of the screen you will see two boxes that house multiple features. The top box is where your data lives. Every time you create a new variable you will see its stats in this box. You can also quickly import datasets by clicking “Import Datasets”. More on that later…
The box at the bottom houses a wide array of features. You will see a list of files associated with the project here. This allows you to quickly switch between files without stopping your work. If you create visualizations, they will populate in the Plots tab. The packages tab will show you the packages available to your for your project and the help tab will populate when you ask R for help in the console.
Each of these boxes can be expanded or collapsed using the square icons in the upper right corner of the module. You can also change the size of the columns or boxes by dragging the thick grey bar that separates each module.
Everybody I know sets up their RStudio dashboard a little differently. I like to keep all four boxes relatively the same size, as you see in the picture above. I rarely collapse windows because it helps me see all of the working pieces of my projects. R is not very intuitive on its own. A well structured RStudio dashboard is vital to your data analysis success. As you learn and continue to use RStudio you will find new ways to set it up in a meaningful way for you.
Do you have any tips or tricks for using RStudio? Drop them in the comments below. I would love to learn from you!