Lesson 0 - Using RStudio
This lesson will go over some of the functionality and features that RStudio provides.
Table of Contents
Lesson Objectives
- Understand how to use RStudio
RStudio
A typical RStudio window has 4 important sections. The source code, the console, the environment, and a fourth section for files, plots, packages, or help.
Source Code
This is the section where you’ll be writing all your R code. You can also save your R code to a file to come back to it easily.
If you don’t see this section, go to
File
>New File
>R Script
. This should make the source code section appear.
Console
The console will show you the output of your code and any errors that you may come about. You can also type R commands directly into the console to run them.
Environment
In the environment section, you can see all currently stored data. If you want to start from a clean slate, you can use the brush button to wipe your environment clean.
Other
This last section has everything else you might need. A file explorer window, an area to view plots/graphs, a list of currently installed packages, and a section to get help.
Creating and Running Code
Any code you want to be able to rerun in the future should be written in the source code area and saved to a file.
To run a line of code, click on the line you want to run and click on the Run
button.
Alternatively, you can also use the Ctrl
+ Enter
keyboard shortcut.
If you want to run multiple lines of code at once (or the entire file), highlight the portions you want to run and use the Run
button (or the shortcut) to run the code.
If you want to work with your data interactively, you can also run R commands in the console. This is most useful for testing and debugging purposes.
Installing Packages
Packages are extensions to the R programming language. They provide additional functionality, whether that be datasets or functions. With R, you have access to ~20,000 packages.
To install packages in R, navigate to the Packages
section in the bottom right area. You’ll see a list of enabled and disabled installed packages. If you don’t see the package you want, you can click on the Install
button and search it by name.
Getting Help
To get help with anything in the R programming language, you can use the help panel.
If you need help with a particular function, type ?functionName
in the console. This will open up the function’s help page.
Key Points / Summary
- RStudio brings a lot of features to help with programming.
- You can type
?functionName
to get a help page for that function.