In this chapter, we provide a basic introduction to the R system (R Development Core Team (2005)): where to get R, how to install R and upgrade R packages. We also show how easy it is to use R to simulate and analyze data from a simple clinical trial. We conclude the chapter with a brief summary and some recommendations for further reading and references. Readers who already know and have familiarity with R can skip this chapter and go directly to any of the remaining chapters.
1.1 What is R?
To obtain an introduction to R, go to the official homepage of the R project at
http://www.R-project.org
and click âAbout Râ under âR Projectâ:
To some users, âfreeâ software may be a ânegativeâ word for software that is difficult to use, has lower quality or utilizes procedures that have not been validated or verified, etc. However, to other users, âfreeâ software means software from an open source that not only allows use of the software, but also permits modifications to handle a variety of applications. This latter description is the fundamental principle for R system.
We now proceed to the steps for installing and using R.
1.2 Steps on Installing R and Updating R Packages
In general, the R system consists of two parts. One is the so-called R base system for the core R language and associated fundamental libraries. The other consists of user contributed packages that are more specialized applications. Both the base system and the packages may be obtained from the Comprehensive R Archive Network (CRAN) from the weblink:
http://CRAN.r-project.org
Installation of R system is described in the following sections.
1.2.1 First Step: Install R Base System
The base system can be downloaded from
http://CRAN.r-project.org
for different platforms of âLinuxâ, âMacOS Xâ and âWindowsâ. In this book, we illustrate the use of R for âWindowsâ. âWindowsâ users can download the latest verison of R using the link:
http://CRAN.r-project.org/bin/windows/base/release.htm
(At the writing of this book, version R 3.3.1 is available.) To download and install R to your computer, simply follow the instructions from the installer to install R to the âProgram Filesâ subdirectory in your C. You are ready to use R for statistical computing and data analysis.
Note to LATEX and R/Sweave users: LATEX will complain about the extra space in the path as in âProgram Filesâ. Therefore if you want to use R along with LATEX, you need to make a subdirectory without space in the path to install R.
You should now have an icon with a shortcut to R. Simply click the icon to start R. You should see some introductory information about R and a command prompt â>â:
>
To illustrate R computation, suppose we wish to calculate the sum of 1 and 2. The first line of R computation is:
> x = 1+2
The computed value may be printed using:
> print(x)
[1] 3
You should get â3â.
1.2.2 Second Step: Installing and Updating R Packages
The R base system contains a variety of standard statistical functions, descriptive and inferential statistical analysis methods, and graphics which are appropriate for many statistical computing and data analysis requirements.
However, the packages are more specialized applications that are contributed by advanced R developers and users who are experts in their field. From our view, packages in R is the most important component in R development and upgrading. At the time of writing this second edition of our book, there are more than 9203 packages in the R system spanning almost all fields of statistical computing and methodology.
You may install any packages from the R prompt by clicking install.packages from the R menu Packages.
For example, for researchers and practitioners who are interested in designing group sequential clinical trials, the gsDesign contributed by Keaven Anderson from Merck and Company can be installed from this pull-down manual. All the functionality of this package is then available by loading it to R as:
> library(gsDesign)
For first-time users for this package, information about its use may be obtained by invoking:
> library(help=gsDesign)
A help page is then available which explains all the functionality of this package. For readers who desire a comprehensive list of available packages, go to
http://CRAN.R-project.org/src/contrib/PACKAGES.html
1.2.3 Steps to Get Help and Documentation
A striking feature of R is the easy access of its âHelp and Documentationâ which may distinguish it from other software systems. There are several ways to access âHelp and Documentationâ.
The general reference may be obtained from RGui in R. When R is started, click âHelpâ to access R help items on âFAQ on Râ, âFAQ on R on Windowsâ, âManuals (in PDF)â, etc. We recommend that readers print the online PDF manual âIntroduction to Râ for future reference.
Additional âHelp and Documentationâ may be obtained from the R home-page. Many documentations and online discussions on R are available from the R homepage http://www.r-project.org/. The online âDocumentationâ section consists of almost a...