The four RStudio Windows

When you open RStudio, you'll see the following four windows (also called panes) shown in in Figure one.seven. Still, your windows might be in a different order that those in Figure 1.7. If you lot'd similar, you can change the order of the windows nether RStudio preferences. Yous tin can also change their shape by either clicking the minimize or maximize buttons on the top right of each panel, or by clicking and dragging the heart of the borders of the windows.

The four panes of RStudio.

Effigy one.vii: The four panes of RStudio.

At present, allow's see what each window does in detail.

Source - Your notepad for code

The Source contains all of your individual R scripts. The code won't be evaluated until you send it to the Console.

Figure ane.viii: The Source contains all of your individual R scripts. The code won't be evaluated until you ship it to the Console.

The source pane is where you create and edit ``R Scripts" - your collections of code. Don't worry, R scripts are just text files with the ".R" extension. When y'all open RStudio, it will automatically kickoff a new Untitled script. Before you start typing in an untitled R script, you should e'er save the file under a new file proper name (like, "2015PirateSurvey.R"). That fashion, if something on your calculator crashes while you're working, R will have your lawmaking waiting for you when you re-open RStudio.

You'll detect that when yous're typing code in a script in the Source console, R won't actually evaluate the code as y'all type. To have R actually evaluate your code, you need to first 'ship' the code to the Console (nosotros'll talk nigh this in the next section).

There are many ways to send your lawmaking from the Source to the console. The slowest fashion is to copy and paste. A faster way is to highlight the code you wish to evaluate and clicking on the "Run" button on the summit correct of the Source. Alternatively, yous can use the hot-key "Control + Return" on Mac, or "Control + Enter" on PC to send all highlighted code to the console.

Console: R's Heart

The console the calculation heart of R. All of your code will (eventually) go through here.

Figure 1.9: The console the calculation heart of R. All of your code will (eventually) go through hither.

The panel is the eye of R. Here is where R actually evaluates code. At the start of the console you'll see the character . This is a prompt that tells you that R is prepare for new code. Y'all tin can blazon code directly into the console afterwards the prompt and get an immediate response. For example, if you lot blazon 1+1 into the console and press enter, you'll meet that R immediately gives an output of 2.

Effort computing 1+1 by typing the code straight into the console - then press Enter. Yous should come across the result [1] 2. Don't worry about the [1] for now, we'll go to that afterward. For now, we're happy if nosotros just come across the 2. So, blazon the same code into the Source, and and then transport the code to the Panel past highlighting the code and clicking the ``Run" button on the elevation right hand corner of the Source window. Alternatively, you tin utilise the hot-central "Command + Return" on Mac or "Control + Enter" on Windows.

Tip: Effort to write near of your code in a document in the Source. Merely type straight into the Console to de-bug or do quick analyses.

So as yous tin can see, y'all can execute lawmaking either by running it from the Source or past typing it straight into the Console. However, 99% nigh of the time, yous should exist using the Source rather than the Console. The reason for this is straightforward: If you type code into the console, it won't be saved (though you can look back on your command History). And if you lot make a error in typing code into the panel, you'd accept to re-type everything all over once again. Instead, it'south better to write all your code in the Source. When you are prepare to execute some code, you tin can so send "Run" it to the console.

Surroundings / History

The environment panel shows you all the objects you have defined in your current workspace. You'll learn more about workspaces in Chapter 7.

Figure 1.10: The surround panel shows you lot all the objects you have defined in your electric current workspace. You'll learn more about workspaces in Chapter 7.

The Environs tab of this panel shows you the names of all the data objects (like vectors, matrices, and dataframes) that yous've defined in your electric current R session. You can likewise run across information like the number of observations and rows in data objects. The tab also has a few clickable actions like ``Import Dataset" which will open a graphical user interface (GUI) for important information into R. Yet, I nearly never wait at this menu.

The History tab of this console simply shows you a history of all the code you've previously evaluated in the Console. To be honest, I never look at this. In fact, I didn't realize it was even in that location until I started writing this tutorial.

As you get more comfy with R, y'all might observe the Environs / History panel useful. But for now yous can merely ignore it. If you want to declutter your screen, you can fifty-fifty just minimize the window by clicking the minimize push on the top correct of the panel.

Files / Plots / Packages / Help

The Files / Plots / Packages / Help panel shows you lot lots of helpful information. Let'southward go through each tab in detail:

  1. Files - The files console gives you lot access to the file directory on your hard drive. Ane squeamish feature of the "Files" console is that yous can use information technology to set your working directory - once you navigate to a folder you desire to read and save files to, click "More" and so "Set Every bit Working Directory." We'll talk about working directories in more detail presently.

  2. Plots - The Plots console (no big surprise), shows all your plots. There are buttons for opening the plot in a separate window and exporting the plot equally a pdf or jpeg (though you can as well do this with code using the pdf() or jpeg() functions.)

Let'south see how plots are displayed in the Plots panel. Run the lawmaking on the right to display a histogram of the weights of chickens stored in the ChickWeight dataset. When you do, yous should come across a plot like to the 1 in Figure ane.xi show up in the Plots panel.

                              hist(x =                ChickWeight$weight,                main =                "Chicken Weights",                xlab =                "Weight",                col =                "skyblue",                edge =                "white")            

The plot panel contains all of your plots, like this histogram of the distribution of chicken weights.

Effigy 1.11: The plot console contains all of your plots, like this histogram of the distribution of craven weights.

  1. Packages - Shows a listing of all the R packages installed on your harddrive and indicates whether or not they are currently loaded. Packages that are loaded in the current session are checked while those that are installed just non nonetheless loaded are unchecked. We'll hash out packages in more detail in the next department.

  2. Aid - Help menu for R functions. You can either type the name of a function in the search window, or use the code to search for a function with the name

              ?hist                # How does the histogram function work?                ?t.test                # What about a t-test?