R Introduction

R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS.

Official site: http://www.r-project.org/index.html

Basic command

The general form is

R CMD command args

where command is the name of the tool and args the arguments passed on to it.

Currently, the following tools are available.

BATCH: Run R in batch mode. Runs R –restore –save with possibly further options (see ?BATCH).

COMPILE: (UNIX only) Compile C, C++, Fortran … files for use with R.

SHLIB: Build shared library for dynamic loading.

INSTALL: Install add-on packages.

REMOVE: Remove add-on packages.

build: Build (that is, package) add-on packages.

check: Check add-on packages.

LINK: (UNIX only) Front-end for creating executable programs.

Rprof: Post-process R profiling files.

Rdconv: Rd2txt Convert Rd format to various other formats, including HTML, LaTeX, plain text, and extracting the examples. Rd2txt can be used as shorthand for Rd2conv -t txt.

Rd2pdf: Convert Rd format to PDF.

Stangle: Extract S/R code from Sweave or other vignette documentation

Sweave: Process Sweave or other vignette documentation

Rdiff: Diff R output ignoring headers etc

config: Obtain configuration information

javareconf: (Unix only) Update the Java configuration variables

rtags: (Unix only) Create Emacs-style tag files from C, R, and Rd files

open: (Windows only) Open a file via Windows’ file associations

texify: (Windows only) Process (La)TeX files with R’s style files


R CMD command --help


So if you are going to compile R program just enter:

R CMD BATCH <your R program>


R package

Check out R package route, enter R shell and enter:

> .libPaths()

References: http://stackoverflow.com/questions/2615128/where-does-r-store-packages

R install package

Method 1: Install from source

Download the add-on R package, say mypkg, and type the following command in Unix console to install it to /my/own/R-packages/:

$ R CMD INSTALL mypkg -l /my/own/R-packages/

Method 2: Install from CRAN directly

Type the following command in R console to install it to /my/own/R-packages/ directly from CRAN:

install.packages(“mypkg”, lib=”/my/own/R-packages/”)

Load the library

Type the following command in R console to load the package

library(“mypkg”, lib.loc=”/my/own/R-packages/”)

References: http://math.usask.ca/~longhai/software/installrpkg.html

Steps to Build an R package

  • Step 1. Prepare your functions

  • Step 2. Build the structure of the package using package.skeleton()

  • Step 3. Edit DESCRIPTION File

  • Step 4. Edit the help File

  • Step 5. Preparation for Windows Users (RTools)

  • Step 6. Build and install the R package

  • Step 7. Check the R package

  • Step 8. Add functions and data to a package


  • http://www.stt.msu.edu/~cui/Groupmeeting/R_package_tutorial.pdf
  • http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf

I’ve collected some of the basic usage of R languages on github:


Go and check it out! :) happy coding!