9. R

You can run R in the Unix command line. To do this, simply type R. If you have X11 forwarding on in your ssh session, using the -X option, you will be able to see graphical devices that R opens when you for example plot something

This essentially turns the command window into the R console you're familiar with. From here, you can do all of the same things as you can in regular R. There are a few things worth noting:

Reading files

Alas, the command line is completely mouseless, so the file.choose() command for reading data using read.table() or read.csv() is no longer available. Instead, type in the name of the file you want in inverted commas. Fortunately, R will look for the file in the working directory you were in when you started the console, so it may actually be even more straightforward. However, if you're not in the same directory, you'll need to type the path the same way as you would when you're copying, moving, or navigating files & folders.

mydata <- read.table("data.txt", header=T)
otherdata <- read.csv("work-monthly/RData/data.csv")

Creating pdf file of a plot

Unless you're using X11 forwarding, you won' t be able to see any plots you've made in R. Even if you are, once you've made the plot you want for your paper, you'll still need to save it. R can do this by opening its own workspace inside a pdf file, called a 'device'. Other devices include the Quartz & X11 windows you're already familiar with looking at your plots on.

First, call the pdf() function to tell it what the file should be called, then make your plot as you like it. To stop working in that file call the function. You can then download it from the server to view it.


More information on R's ability to use devices (it can do more than just PDFs, and also have several open at once) can be found in the help files, ?pdf etc.

QMUL logo