Navigating R Studio for programming
1 The four panes of RStudio
File, Console, Environment, and Files tabsBy default, RStudio opens with four panes. All but the top left one even have several tabs with their own menu bars. In this tutorial, I will call the panes with the names of the tabs in focus.
2 Console
Command line of the bare R
Type a command (e.g.
1 + 1) and hit Enter to execute it.Console displays the output.
>at line start: R is ready to accept your next commandConsole does not save your scripts. Use files to save your work.
Clear Console: hit the broom icon or
Ctrl + L.
3 File formats for writing scripts
Quarto, R Notebook, and R Markdown are markdown-based formats you have learned about. They are fantastic when you need to accompany your code with text and report the results in a single file. But not all scripts require fancy presentation. If you just want to do something quick (but still worth saving for later reuse), you may prefer the bare R Script file (.R). It comes as an empty plain text file with the .R suffix.
4 Run a script with comments
In this format, R reads each line as a command and will throw an error and stop at each line it cannot execute. When you want (you should) comment your code, you must put a fence # before the text to tell R to ignore it.
5 Environment pane
lists objects currently loaded in R
variables
functions you have written
Delete objects with the broom icon.
Toggle List and Grid view.
Grid view can mark individual objects for deletion.
What you see is the so-called Global Environment. Each software library (aka software package) that you load (more later) will create its own environment. In this course, we will only consider the Global Environment.
6 Packages pane
You typically install packages from https://cran.r-project.org/
A package sometimes has dependencies; i.e., requires other packages to work correctly. When you check Install dependencies, R will load all missing dependent packages automatically. CRAN is the official repository of R packages. But you can as well download a package from GitHub or elsewhere. You just adjust the source with Configuring Repositories in the Install menu.
7 Get Help
- Roll down menu top left pane
- Help tab in bottom right pane
- https://stackoverflow.com/questions
- MS Copilot, ChatGPT & Co. quite good.
- Wickham et al.: R for Data Science
- Grolemund: Hands-On Programming with R
- https://www.tidyverse.org/
8 Plots pane
- plots output from Console/R file
- you can export them interactively
Plots pane