Skip main navigation

What is R in computing?

R is a vehicle for newly developing methods of interactive data analysis and it has been extended by a large collection of packages

R is a “language and environment for statistical computing and graphics”. R is an integrated suite of facilities for data manipulation, calculation and graphical display.

Among other things it has:

  • An effective data handling and storage facility
  • A suite of operators for calculations on arrays
  • A large, coherent, integrated collection of intermediate tools for data analysis
  • Graphical facilities for data analysis and display either directly at the computer or on hard-copy

R is very much a vehicle for newly developing methods of interactive data analysis. It has developed rapidly, and has been extended by a large collection of packages.*

How to work under R

Step 1. In your bash window, create a new working sub-directory (we recommend you use separate working directories for analyses conducted with R, here under Desktop), and move to it

$ cd Desktop
$ mkdir exerciseR 
$ cd exerciseR

Step 2. Start the R program by simply typing R

$ R

This command will open the R environment for you, and a new prompt will appear: “>

Step 3. To work under R, write any command following the “>” prompt as in Unix

> 

Example of basic operations in R:

> x = 3
> y = 2
> x + y
[1] 5

Step 4. R being created for statistical purposes, it has very helpful built-in functions

> sqrt(3 * 4 + 2 * 5 + 3)
[1] 5
> log(5) + log(10)
[1] 3.912023
> log(50) 
[1] 3.912023
> sum(3 * 4 + 2 * 5 + 3)
[1] 25

Where sqrt=square root, …

Step 5. When working under your current R session, the entities (variables, functions, etc…) that R (you) creates and uses are called ‘objects’.

To display the names of the objects, there are two options:

> objects() 
> ls()

Step 6. As in Unix, to remove the two ‘objects’ (in this example called x and y) you can use rm

> rm(x, y) 

Step 7. To quit R

> q() 

You will be asked whether you want to save your workspace image

> q()
Save workspace image? [y/n/c]:

Where y=yes (save data and quit), n=no (quit without saving data) and c=cancel (abort the request and continue working under the current R session).

If you choose ‘y’, your objects will be saved in an ‘.RData’ file, and the command lines in a ‘.Rhistory’ file

Important things to know

Note 1. As in Unix (man), obtaining help for functions is possible in R (help or ?). Example to obtain information on a command called sum

> help(sum)
> ?sum

To close this sub-section type “q”

Note 2. A “+” symbol might appear when you try to execute a command

+ 

This means R is expecting you to complete your command

Note 3. As Unix, R is case sensitive

> help(sum)
> HELP(sum) 

The first command will work, the second will output Error in HELP(sum): impossible to find the function “HELP”

Note 4. As for Unix, you can use the upwards arrow on your keyboard (↑) to go back to the previous command you used.

Note 5. A very detailed introduction on how to use R can be found in https://cran.r-project.org/doc/manuals/r-release/R-intro.html

*Please note that these are official definitions of R taken from https://www.r-project.org/ and http://mercury.webster.edu/aleshunas/R_learning_infrastructure/Introduction_to_R_and_RStudio.html)

© Wellcome Genome Campus Advanced Courses and Scientific Conferences
This article is from the free online

Bioinformatics for Biologists: An Introduction to Linux, Bash Scripting, and R

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now