This page provides links to introduce you to the RStudio environment.
Did you lose track of one of your window panes? Use the View tab in the top bar to return to a view with all panes
Is the white RStudio background burning your retnas? Need a change of scenery? No need to go outside!
In the top bar, go to Tools > Global Options, and then select “Appearance”:
You can find me mashing the following keys in Windows:
Shortcut | Keys (Windows) | Keys (MacOS) |
---|---|---|
Run a line of code | (With typing cursor on line) ctrl + enter | (With typing cursor on line) cmd + enter |
Run a chunk of code | (With typing cursor in chunk) ctrl + shift + enter | (With typing cursor in chunk) cmd + shift + enter |
Create a new chunk | ctrl + alt + i | cmd + option + i |
Type a pipe | ctrl + shift + m | cmd + shift + m |
Type an assignment operator | alt + - | option + - |
Stop running | (In Console) esc | (In Console) esc |
If for some reason your code is hitting an error, here are some useful commands you might run in your RStudio Console to help troubleshoot:
Command: ?functionName
What it does: Pulls up the documentation for
whatever you type in place of functionName
, and displays it
in the Help window. A function’s documentation is often (but not always)
the final word on how a function is meant to behave in R. It will
provide information on the function’s
arguments (and their default values), the resulting output
(“Values”), and will give you examples of how to implement that
function.
Command: sessionInfo()
What it does: If you’re experiencing issues with a certain package, maybe it’s time for an update. You can check your current version of R using this command. Find information on specific packages by using the argument ‘package = packageName’.
You can also find which version of RStudio you have by running
RStudio.Version()
Command: traceback()
What it does: If your code keeps hanging up on an error, you can often find clues as to why it’s happening by viewing the underlying code that’s causing your code to halt. Traceback will print the list of functions that were called before the error occurred. It’s literally “tracing your steps” right before the error happened. The language itself in the traceback is usually pretty cryptic and hard to read at first. Don’t let that stop you from looking at it when you encounter problems.
Command: object_size()
What it does: For the purposes of this lab, you most
likely won’t need to worry about your computer’s RAM. Nevertheless, the
nerds among us might find it interesting to inspect the size of an
object that we’ve saved to our R Environment. Use
object_size(objectName)
to inspect a given object.
Alternatively, inspect overall RAM usage and limitations with
memory.size()
and memory.limit()
.
R Studio will be the launching pad for all of our lab assignments in this course.
The RStudio environment itself can feel overwhelming at first. Luckily, there are excellent resources already available to help get you acquainted:
For those of you who prefer to learn by reading, this website’s first tutorial, “Getting started with R/RStudio”, is a good place to start.
Dr. Eric Green used to run a summer workshop called “I Eat Data Science for Breakfast”. He gives a stellar tutorial to the RStudio environment starting at 10:49 in his Week 1 video.