I adapted this blog post from a chapter in my upcoming book, R Programming in Plain English. You may download a PDF of all completed material for this book here.
RStudio is an IDE (integrated development environment) that allows more interactivity and for you to visually keep track of what you’re doing.
In simpler words, it’s a handy user interface for programming in R.
It’s far easier to both get started and understand the R programming language by using RStudio. It makes importing data and packages easier. It also makes it easier to manage and visually review what data and packages you have already loaded. And finally, it’s just plain nicer looking.
How to Download RStudio
Note: You must download base R before you can use RStudio. Read this post for how to do that.
Scroll down and you’ll see a big blue button to download the latest version of RStudio.
You can tell that RStudio was designed for the end-user in mind by how painless it is to download compared to base R.
Go ahead and install it once the download finishes.
You'll see an icon like this appear in your applications folder. Go ahead and open it.
Understanding the RStudio Interface
The RStudio interface is broken up into four panes. The default pane setting has the following:
Environment, History, and Connections
Files, Plots, Package, Help, and Viewer
RStudio Source Pane
The source pane on the top left is a handy one.
This pane displays previously saved or new R scripts you wrote in the past.
You may not be able to see this pane yet. Especially if you've never opened or saved a script before. To view the source pane, go to the top menu and click File, New File, and then R Script.
The source pane can also show loaded data sets as well.
This is a step up over R base, which is limited when you want to view extremely large data sets. This is where RStudio really comes in handy. Down below is the same Census data set in R base:
As you can see, RStudio's source pane makes this a lot easier to visualize.
RStudio Console Pane
The console pane on the bottom left is more or less the same as the base R console we reviewed earlier. It allows you to enter commands.
However, you won’t be able to save those commands as a script unless you write them in the source pane above.
This pane also has a Terminal and an R Markdown tab (if you have the latter installed). The Terminal tab allows you to enter commands to interact with your computer. IT professionals use this frequently.
R Markdown may not appear for you yet. I'll explain what R Markdown in a later post, but this tab merely shows the log for producing an R Markdown export.
RStudio Environment, History, and Connections Pane
The top right pane includes environment, history, and connections as tabs.
Environment is very handy and it’s something that sets RStudio apart from the base version. It shows objects with assigned names that are saved in your environment.
I cover objects in detail here. Along with packages, they’re the most important component of R programming. What you need to remember here is that the environment tab in this top right pane tells you what you have saved.
The history section is one I don’t use too often, but I could see why some people would find it handy. It tells you what commands you’ve run during your R session. So anything you input in your console will show up here as a record.
The connection tab is useful for those who want to connect to a database or data warehouse.
If you’re a researcher, you may not use this much. If you work with databases in any capacity, this will make it easier to simply query data directly from the database, as opposed to importing it in via CSV files or spreadsheets.
RStudio Files, Plots, Packages, Help, and Viewer Pane
The bottom right pane makes R a lot easier to manage. It contains a separate tab for:
I’m going to start with the packages tab. Packages are what makes R programming such a flexible language. It allows you to import functions to suit your needs.
This is a useful little tab. It tells you if a package needs to be installed or loaded. If a package doesn't show up in this list, you can install it easily. If it does show up in this list, you can easily click the little box next to its name and it'll load.
Plots is a tab that displays any plots you create using graphical commands.
Help is a super "helpful" tab. You can find the extensive R documentation there that explains R and how it operates. It also will display information you look up on packages and functions you download.
If you ever add a ? before a function, it will display the documentation in the help section.
If you add ?lm to your console and execute, you'll see documentation on the function in the help tab.
Don’t forget about this trick! It helps a lot!
Files and the viewer tab are ones I’ve seldom used.
I won’t go into too much detail, but the files tab displays all the files you can open in RStudio for a given folder. This is helpful because you don't have to specify a file path when loading files listed here.
The viewer tab allows you to view web content. I’ve never used it for that purpose. I like good ol’ fashioned web browsers myself