3.4 Taking Stock
If you have either installed the software or signed up to the Posit Cloud correctly, you should now be able to open Rstudio (or your Cloud account) and see a screen that looks something like this:

Figure 3.2: Welcome to R!
The window on the left is your Console which is exactly what you would see if you opened up R directly.8 The window on the upper-right is your Global Environment. It will show you all of the data sets, variables, and result objects that are currently in R and available to you. Note that it is currently empty because we haven’t done anything yet. The window on your bottom-right has several useful tabs that let us look at our folder directory (as shown) as well as any figures we generate and R packages at our disposal.
This is the default mode of Rstudio. You can input commands into the console right at the prompt “>” and R will execute them line by line. This is fine if you wish to execute one single command at a time, but it becomes tedious if we have a series of commands we need to execute before we arrive at our desired result. We can therefore alter this default mode by adding R-scripts.

Figure 3.3: An R-script!
Clicking on the green plus in the upper left of the screen will give you the option of opening an R-script. An R-script window will now appear and take up half of what was once our console space. An R-script is really nothing more than a text file. We can type several commands in sequence without running them line by line (which we would need to do if we typed them into the console). Once the commands are typed out, we can highlight them all and hit that run button on top. The commands get sent to the console and you’re off…

Figure 3.4: Running Commands from R-scripts!
The picture above is just a quick example of what an R-script can do. Line 3 tells R to plot all of the variables in a dataset called mtcars. Highlighting that line and hitting the run button sends the command to the console below, and the plot figure shows up in the Plots window. That’s that!
Note that we will never open R by itself, because it is easier to communicate with R through Rstudio.↩︎