Skip to main content Skip to navigation

R Preliminaries, Basic R commands

R Preliminaries

R is very sensitive to how you type things in. It matters whether you use capital letters or not, and whether you leave spaces between things you type. If you get an unexpected result this is the first thing you should check. You will be provided with a file containing some basic commands (sample_r_commands.txt [Text]).

To run a command all you do is type it in and press enter. Rather than retyping something you have typed in before, the up arrow key will allow you to scroll through all the commands you have typed in. If a calculation is being very slow, or you have sent R into an infinite loop, it may be possible to abort it using the escape key.

Basic R commands

For this step it is important that you have sample_r_commands.txt [Text] available on your computer. If you haven't already got it download it now.

You might want to print out a copy of this so you can write your own notes and comments about it, but this isn't necessary. Open up R if you don't already have it open. Load the aforementioned text file using File->Open Script (you may have to choose 'all files' as the file type to see it.)

The file is structured in sections: comments (lines starting #) and commands (lines without #'s).

To run a command you need to type it into the main R window called 'R console' and then press enter, as mentioned before be very careful with you spelling, spacing and CaPiTaliZation; as R is sensitive to all these things.

Or, you can highlight the bit of code you want to run, and press CTRL+r which is a real time saver.

Some of the comments will tell you to do things outside of R. We have already done the first of these:

#Rearrange data (.soft files and .annot files) into tab delimited
#text format (*.txt), with column headings as the first row in Excel.

So we can continue when we get to this point.

The document is meant to be worked through at your own pace; some of you will go faster than others.

The next section details how to find help in R. If you read this before you start working through then you will know how to find more help on the commands you are using. Do feel free to try different changing things slightly with the commands if you desire. There will be helpers in the class should you get stuck.