Download R from here. Select a hosting site, for example,
we may select USA -> http://watson.nci.nih.gov/cran_mirror/ (National Cancer Institute, Bethesda, MD).
Next select "Download R for Windows". Click into "base", then click "Download R 3.xx.x for Windows". Save the file on your
computer, or you may start install by click "Run" button instead.
Click the downloaded file "R-3.xx.x-win.exe" to start installation. You may accept all default
setting and click next all the way to finish the R installation. By default, there will be a R shortcut on the desktop after installation. The R can be started by clicking
that icon.
The default working directory should be "C:/Users/xxx/Documents/". To check the working directory,
type getwd(). There are several methods to change the default working directory.
1. Open a random folder, click "Desktop" icon on the up left to open the desktop directory.
Right click the R shortcut icon, select "properties", change the "Start in" directory.
2. Add R to the PATH environment. Right click "My Computer" -> "Properties" -> "Advanced" -> "Environment
variables", then append the R to the path. You now can start R from the windows shell.
You may use setwd() to temporarily change the working directory.
rpm -ivh R-3.xx.yum install R, or yum update R to get a recent version.
export PATH=".:$PATH:/app/R-3.xx.x/bin". R can then be initiated from any directory
by typing R.
>q()If you select "save Workspace image" during quit, all R objects will be written into a file ".RData" in the working directory, and all history command will be recorded into a file ".RHistory" in the working directory. By default, R will load all objects while starting. This may save time if you want to read a large file, but waste you time if you do not need the objects. You can delete the .RData and .Rhistory under the R working directory to delete all R objects and history commands.
>?plot#show help page for function plot >help(plot) >??plot >help("xyplot",package="lattice") >help("!")#help for operator ! >help.start()#show HTML R help pages >help.search("plot")#show all functions which name has keyword plot
> apropos("test")
[1] ".valueClassTest" "ansari.test"
[3] "bartlett.test" "binom.test"
[5] "Box.test" "chisq.test"
[7] "cor.test" "file_test"
[9] "fisher.test" "fligner.test"
[11] "friedman.test" "kruskal.test"
[13] "ks.test" "mantelhaen.test"
[15] "mauchly.test" "mcnemar.test"
[17] "mood.test" "oneway.test"
[19] "pairwise.prop.test" "pairwise.t.test"
[21] "pairwise.wilcox.test" "poisson.test"
[23] "power.anova.test" "power.prop.test"
[25] "power.t.test" "PP.test"
[27] "prop.test" "prop.trend.test"
[29] "quade.test" "shapiro.test"
[31] "t.test" "testInheritedMethods"
[33] "testPlatformEquivalence" "testVirtual"
[35] "var.test" "wilcox.test"
Execute a R script file:
>source("test.R")
Or under Linux shell:
R CMD test.R
Or under Windows command line like:
C:\Program Files\R\R-3.0.1\bin\R.exe d:\test.R
>sink("output.txt") #Divert output from console to file
>sink() #Restores to the console output
>objects() #Display current objects
>ls() #Display current objects
>rm(x) #Remove object x from R work space
>getwd() #Display current work directory
>data() #Display all built in datasets
>install.packages("mmass") #Install package mmass
>installed.packages() #Display all installed packages
>ls("package:base") #List all functions of R Base
>demo(graphics) #demo of R's graphics capabilities
Sometimes the package may need dependencies. The following command will install the package "dplyr" with all
its dependencies.
>install.packages("dplyr", repo = "http://cran.r-project.org",dep = TRUE)
A package can be installed from a local file. e.g. Let's install package "hash". First download from https://cran.r-project.org/web/packages/hash/index.html,
save the source file as "hash_2.2.6.1.tar.gz", then select "Packages->Install packages from local files...", browse and select the file to install.
>remove.packages("dplyr")
RGui is the default editor for R script. It is located at "~/bin/x64/Rgui.exe" after R installation.
You may use the upward and downward arrow to recall and reexecute previous commands.