Biomedical Engineering Theory And Practice/Introduction of R
What is R?
R is a open source commandline programming language for statistical computing and graphics. 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. 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. Some highlights are listed below.
|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++, Java, .NET  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 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 https://journal.r-project.org. https://journal.r-project.org 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
- Go to http://www.r-project.org/.
- Click on the download R link.
- Then select a location closest to you.
- 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. Work on RStudio started at around December 2010, and the first public BETA version (v0.92) was officially announced in February 2011. 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
R is quite powerful, incorporating packages which are collections of R functions, data, and compiled code in a well-defined format. 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. 
- R packages availability
- 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()  ".GlobalEnv" "tools:rstudio" "package:stats" "package:graphics" "package:grDevices"  "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.
Information on package ‘PK’ Description: Package: PK Version: 1.3-2 Date: 9. August 2013 Title: Basic Non-Compartmental Pharmacokinetics Author: Thomas Jaki <firstname.lastname@example.org> and Martin J. Wolfsegger <email@example.com> Maintainer: Thomas Jaki <firstname.lastname@example.org> 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 http://cran.utstat.utoronto.ca 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 http://cran.utstat.utoronto.ca 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 http://cran.utstat.utoronto.ca
- Remove packages
How to Enter Data
- Sequential Data
> x<-1:15 > x  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- Non-Sequential Data
- List Object
x <- read.csv("Degas.txt", sep=";",header=FALSE, comment.char="\\") somedata<-read.table(file="/home/hanjind/Rworkspace/NMR.csv",header=TRUE,sep=",")
connection<-dbConnect(driver,user,password,host,dbname) mouse1<-dbSendQuery(connection,"SELECT*FROM AHW")
example.3 <- read.table("http://www.unt.edu/rss/class/Jon/R_SC/Module3/ExampleData3.txt",header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE)
png(filename="your/file/location/name.png",height=295,width=300,bg="white") plot(fit) dev.off()
Starting R project or Open R file
- Fox, John and Andersen, Robert (January 2005) (PDF). Using the R Statistical Computing Environment to Teach Social Statistics Courses. Department of Sociology, McMaster University. http://www.unt.edu/rss/Teaching-with-R.pdf. Retrieved 2006-08-03.
- Gentleman, Robert (9 December 2006). "Individual Expertise profile of Robert Gentleman". Archived from the original on 23 July 2011. http://web.archive.org/web/20110723215206/http://myprofile.cos.com/rgentleman. Retrieved 2009-07-20.
- "R News". https://cran.r-project.org/src/base/NEWS. Retrieved 2014-07-03.
- Eddelbuettel, Dirk; Francois, Romain (2011). "Rcpp: Seamless R and C++ Integration". Journal of Statistical Software 40 (8). http://www.jstatsoft.org/v40/i08.
- Temple Lang, Duncan (6 November 2010). "Calling R from Java". Nuiton. http://www.nuiton.org/attachments/168/RFromJava.pdf. Retrieved 18 September 2013.
- "Making GUIs using C# and R with the help of R.NET". http://psychwire.wordpress.com/2011/06/19/making-guis-using-c-and-r-with-the-help-of-r-net/.
- "R.NET homepage". http://rdotnet.codeplex.com/.
- Haynold, Oliver M. (April 2011). "An Rserve Client Implementation for CLI/.NET". R/Finance 2011. Chicago, IL, USA. http://www.rinfinance.com/agenda/2011/OliverHaynold.pdf.
- Verzani, John. Getting Started with RStudio. O'Reilly Media, Inc. p. 4. ISBN 9781449309039.
- "portable download of java dependencies · rstudio/rstudio@484cb88 · GitHub". Github.com. 2010-12-07. https://github.com/rstudio/rstudio/commit/484cb884c28913c19822c42b0cd099ee22832211. Retrieved 2015-05-01.
- "RStudio, new open-source IDE for R | RStudio Blog". Blog.rstudio.org. http://blog.rstudio.org/2011/02/28/rstudio-new-open-source-ide-for-r/. Retrieved 2015-05-01.
- Robert A. Muenchen (2012). "The Popularity of Data Analysis Software". http://r4stats.com/articles/popularity/.