Biomedical Engineering Theory And Practice/Introduction of R

From Wikibooks, open books for an open world
Jump to navigation Jump to search

What is R?[edit]

R is a open source commandline programming language for statistical computing and graphics[1]. R is freely available under GNU license. It is useful in various area such as Business, Industry, Government, Medicie and Academia. R was initially started by Robert Gentleman and Ross Ihaka in 1993—also known as “R & R” of the Statistics Department of the University of Auckland[2]. R is based on the S language developed at Bell Laboratories by Rick Becker, John Chambers and Allan Wilks, and also forms the basis of the S-PLUS systems. Since mid-1997 there has been a core group with write access to the R source. The full list of changes is maintained in the "R News" file at CRAN.[3] Some highlights are listed below.

Release Date Description
0.16 1997.04 This is the last alpha version developed mainly by Ihaka and Gentleman.
0.49 1997.04 This is the oldest available source release, and compiles on a limited number of Unix-like platforms. CRAN is started on this date, with 3 mirrors that initially hosted 12 packages.
0.60 1997.12 R becomes an official part of the GNU Project.
1.0 2000.02 Considered by its developers stable enough.
1.4 2001.12 S4 methods are introduced and the first version for Mac OS X is made available soon after.
2.0 2004.10 Introduced lazy loading, which enables fast loading of data with minimal expense of system memory.
2.1 2005.04 Support for UTF-8 encoding, and the beginnings of internationalization for different languages.
2.11 2010.04 Support for Windows 64 bit systems.
2.13 2011.04 Adding a new compiler function that allows speeding up functions by converting them to byte-code.
2.14 2011.10 Added mandatory namespaces for packages. Added a new parallel package.
2.15 2012.03 New load balancing functions. Improved serialization speed for long vectors.
3.0 2013.04 Support for numeric index values 231 and larger on 64 bit systems.

R is an interpreted and command-line programming language. R supports procedural programming with functions and, for some functions, object-oriented programming with generic functions. R can interface with programming languages like C, C++,[4] Java,[5] .NET [6][7][8] and Python.


CRAN, the Comprehensive R Archive Network is the network of the site which contains R source code, R binaries, extension Packages, Documentation and FAQ. left menu of CRAN website consist of CRAN, About R, software and Documentation.

CRAN(The Comprehensive R Archive Network)

CRAN menu in CRAN mirror is composed of Mirrors, What's new?,Task Views and Search.'Mirrors' in CRAN mirror shows how to download and install R according to your location and platforms. And frequently asked questions and answers are here. 'What's new?'report changes in R, bug fixes in R including the anounce of the new package.'Task views' organized R packages according to the specific field. 'Search' linked some website which can search help files, manuals, and mailing list archives.

About R in CRAN consists of R Homepage and R journal. R Homepage links to The R Project for Statistical Computing. R journal links to is the open access, refered journal of the R project for statistical computing. It features short to medium length articles covering topics that might be of interest to users or developers of R, including short introductions to R extension packages, hints for programming in R, hints for newcomers and proof how the technique can be used in the certain area of current interest using R. Software in CRAN mirror is composed of R Sources, R Binaries, Packages and Other. Documentation in CRAN mirror consists of Manuals,FAQs and Contributed. Manuals are edited by the R development core team and can be downloaded as PDF files, EPUB files, or directly browsed as HTML.The R FAQ is the general collection and includes useful information for users on all platforms.Contributed contains manuals, tutorials and so on by users.

How to install R[edit]

  1. Go to
  2. Click on the download R link.
  3. Then select a location closest to you.
  4. Click on your operating system (Linux, MacOS X, Windows) and follow directions

If you are a Mac user, download the latest .dmg file and follow the directions.In the case of "Windows", click on "base" and then on the link that downloads R for Windows. (In the link, the current version number appears after “R”.) When the dialog box opens, click "Run" and a “Setup Wizard” should appear. Keep clicking "Next" until the Wizard is finish.


R programming language has a lot of open source graphical user interface including well-known RStudio. The most popular GUI,RStudio is written in the C++ programming language and uses the Qt for its graphical user interface.[9] Work on RStudio started at around December 2010,[10] and the first public BETA version (v0.92) was officially announced in February 2011.[11] RStudio is available in two editions: RStudio Desktop, where the program is run locally as a regular desktop application; and RStudio Server.


RStudio screen is composed of Editor Window,Console Window,Project Window and File/Current Directory/loaded package/Help/Viewer.

Use R Package[edit]

R is quite powerful, incorporating packages which are collections of R functions, data, and compiled code in a well-defined format[12]. The directory where packages are stored is called the library. R, itself, includes a standard set of packages when it is installed. Once installed, they have to be loaded into the session to be used. More than 5,800 additional packages are available at the Comprehensive R Archive Network (CRAN), Bioconductor, Omegahat, Github and other repositories. [13][14]

  • R packages availability
> browseURL("")
  • List of installed packages in the computer or the server. This list is displayed in R editor.
> library()
Warning message:
In library() : library/usr/lib/R/site-library’ contains no packages
  • List of currently active packages in the computer or the server.
> search()
 [1] ".GlobalEnv"        "tools:rstudio"     "package:stats"     "package:graphics"  "package:grDevices"
 [6] "package:utils"     "package:datasets"  "package:methods"   "Autoloads"         "package:base"
  • Install new packages
> install.packages("PK")
Installing package into ‘/home/hanjind/R/x86_64-pc-linux-gnu-library/3.0(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
  • library("<package name>") load the library
  • Documentation of packages could be listed in editor.
> library(help="PK")
 Information on package ‘PK’


Package:            PK
Version:            1.3-2
Date:               9. August 2013
Title:              Basic Non-Compartmental Pharmacokinetics
Author:             Thomas Jaki <> and Martin J.
                    Wolfsegger <>
Maintainer:         Thomas Jaki <>
Depends:            R (>= 2.2.1), utils
Description:        Estimation of pharmacokinetic parameters using
                    non-compartmental theory
License:            GPL-2
Acknowledgement:    Alexander Bauer, John-Philip Lawo and Helmut
                    Schuetz for extensive testing
Packaged:           2013-08-09 18:53:55 UTC; jack
NeedsCompilation:   no
Repository:         CRAN
Date/Publication:   2013-08-10 01:05:38
Built:              R 3.0.2; ; 2015-08-20 03:23:11 UTC; unix
  • Upgrade packages
> update.packages()
--- Please select a CRAN mirror for use in this session ---
Warning: package 'XML' in library '/usr/lib/R/site-library' will not be updated
Warning: package 'lattice' in library '/usr/lib/R/library' will not be updated
Warning: package 'Matrix' in library '/usr/lib/R/library' will not be updated
Amelia :
 Version 1.7.3 installed in /home/hanjind/R/x86_64-pc-linux-gnu-library/3.0 
 Version 1.7.4 available at
Update (y/N/c)?  y
curl :
 Version 0.9.4 installed in /home/hanjind/R/x86_64-pc-linux-gnu-library/3.0 
 Version 0.9.6 available at
Update (y/N/c)?  y
digest :
 Version 0.6.8 installed in /home/hanjind/R/x86_64-pc-linux-gnu-library/3.0 
 Version 0.6.9 available at
  • Remove packages
> detach("package:PK",unload=TRUE)

How to Enter Data[edit]

  • Sequential Data
> x<-1:15
> x
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
  • Non-Sequential Data
> y<-c(3,5,7,1,10,15)
  • List Object
> ls()

Import/Exporting Data[edit]

Flat Files[edit]

x <- read.csv("Degas.txt", sep=";",header=FALSE, comment.char="\\")


mouse1<-dbSendQuery(connection,"SELECT*FROM AHW")

R Objects[edit]



example.3 <- read.table("",header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE)



Starting R project or Open R file[edit]


  1. Fox, John and Andersen, Robert (January 2005) (PDF). Using the R Statistical Computing Environment to Teach Social Statistics Courses. Department of Sociology, McMaster University. Retrieved 2006-08-03. 
  2. Gentleman, Robert (9 December 2006). "Individual Expertise profile of Robert Gentleman". Archived from the original on 23 July 2011. Retrieved 2009-07-20. 
  3. "R News". Retrieved 2014-07-03. 
  4. Eddelbuettel, Dirk; Francois, Romain (2011). "Rcpp: Seamless R and C++ Integration". Journal of Statistical Software 40 (8). 
  5. Temple Lang, Duncan (6 November 2010). "Calling R from Java". Nuiton. Retrieved 18 September 2013. 
  6. "Making GUIs using C# and R with the help of R.NET". 
  7. "R.NET homepage". 
  8. Haynold, Oliver M. (April 2011). "An Rserve Client Implementation for CLI/.NET". R/Finance 2011. Chicago, IL, USA. 
  9. Verzani, John. Getting Started with RStudio. O'Reilly Media, Inc. p. 4. ISBN 9781449309039. 
  10. "portable download of java dependencies · rstudio/rstudio@484cb88 · GitHub". 2010-12-07. Retrieved 2015-05-01. 
  11. "RStudio, new open-source IDE for R | RStudio Blog". Retrieved 2015-05-01. 
  12. quickR
  13. Robert A. Muenchen (2012). "The Popularity of Data Analysis Software". 
  14. Rdocumentation