The R User Interface

Doug Hemken

May 2019

R notes | R User Interface

Working with the R Graphical User Interface

Several user interfaces are available for working with R. Every installation of R includes some version of the standard interface (sometimes also called the "R Console").

You should have some basic familiarity with this standard interface. It may come in handy if you ever need to work on a computer that does not have your favorite interface installed (our favorite is RStudio, which is installed on SSCC Windows computers, but not on our linux computers). And the organization of the standard interface is a good starting point for understanding how other interfaces are arranged. You may even find you enjoy the simplicity of the standard interface.

What follows is a description of the standard interface, the R GUI, for R running on Windows platforms.

The Windows within the R GUI

Within the main R window will be one or more sub-windows. The menus and the toolbar that are available to you, such as they are, change depending upon which window is the current focus.

For the most part, saving the contents of these windows works in the usual way: type Ctrl-S or click File - Save (or something similar) in the menus. Separate windows are saved to separate files of several different types. More on saving files is later.

R Console interface

R Console interface

The R Console

Within R, the main window is labeled "R Console". This opens automatically whenever you start up R.

In the Console you can enter R statements (commands) one at a time. Depending on the statement, the response from R may also be printed in the Console. And the Console is where you will find error messages.

Console window

Console window

There is only one Console window. If you close the Console, you end your R session.

To new users the most familiar way to save the contents of the Console is to click File - Save to file ... in the menus. However, keep in mind that the Console only keeps the last few thousand lines written to it! Other methods of saving Console output are described below.

You will also find it easy to copy-and-paste small blocks of text from the Console to a text editor or word processor. Just keep in mind that the Console is using a monospaced font, so you may have to adjust the font in a word processor.

You will also find that it is useful to be able to clear all text from the Console, to restart with a blank slate. For that, just type Ctrl-L or click Edit - Clear console.

The R Editor

When you are ready to move beyond one-statement-at-a-time typing and processing, you will open a window labeled "R Editor" to edit a script. Click File - New script in the menus to open a blank editor, or File - Open script... to open a file you have saved.

R Editor

R Editor

You can have multiple R Editors open simultaneously.

As you would expect, from the script editor you can run commands one-at-a-time or in groups. You can also run just part of an expression. Highlight the code you want to run, then type Ctrl-Enter or Ctrl-R (or use the "Run line or selection" button in the toolbar, or click Edit - Run line or selection in the menus).

  • To run a single line of code, move the cursor somewhere in the line you want to run and then use Ctrl-R. Keep in mind that one line of code may NOT be a complete (executable) statement.
  • To run a selection, highlight the text you want to run and then use Ctrl-R. Highlighted text can extend to more than one line, or could be just part of a line.
  • To run everything in the Editor, highlight everything with Ctrl-A, then use Ctrl-R.

Save the Editor contents with Ctrl-S or File - Save.

The R Graphics Device

When you use a function like plot() that produces a graphic, the graphics window ("device") is the default place it is produced. If a graphics window is not already open, a new one is produced, otherwise the existing window is reused.

Use to open a new graphics window without closing an existing one.

R Graphics Device

R Graphics Device

Save the contents of the Graphics Device by clicking File - Save as, and picking a type of image file. Graphics can also be saved directly to files, skipping display in the Graphics Device: see below.

The Data Editor

The most common way to look at the data values within a basic data object is to simply print it to the Console by typing the name of the data object at the command prompt.

To view the contents of a data frame or matrix, use fix(dataframe) or View(dataframe) (where dataframe is replaced by the name of your data object. This only works for data frames or matrixes. The fix() function allows you to edit a matrix or dataframe, the View() function does not. You can also click Edit - Data editor ... in the menus, and fill in the name of the data frame or matrix you want to edit.

Changes you may make using the Data Editor are saved to the workspace automatically (more on the workspace and how to save it as a file, below). While the Data Editor is open you cannot run any other code.

You do not save any files from this window.

Data Editor

Data Editor

The R History

Use history() to open your command history in a window. By default this shows you only your last 25 lines of code (as submitted).

R History

R History

To save the contents of this window click File - Save to file or use the function savehistory().

Saving the Workspace

R keeps the data and other objects it works with in an area of your computer’s memory called the "workspace." In the standard R interface, there is no separate window where you can see a list of these objects, but you can generate a list quickly in the Console with the function ls(). The objects here can consist of data you have read in from outside sources (e.g. from text files), new data you have created, data that results from expressions you have run, and also a variety of other objects.

When you shut down R, by default it offers to save your workspace. If you save your workspace with the default name ".Rdata"" (no filename, just the file extension!), then when you start R this workspace will be automatically loaded.

Many of us consider it good practice (for work of substance) to save your data sources and a script that creates all these data objects, so that you (or someone else) can completely reproduce your work. From this point of view, you will seldom need to save the workspace itself.
However, if it takes a long time for your work to be reproduced, or if your script is particularly long and complicated, it can save time and effort to save the workspace to provide an intermediate starting point for your next work session.

To save your workspace click File - Save workspace ... in the menus, or use save.image(). To save your workspace with some other filename, use save(file="filename"). You can load a previously saved workspace with load(file="filename").

More Details on Saving and Using Files

Saving Console output

Saving Scripts

Saving Graphics

Saving the Workspace