R language

#programming-language

Notes and links on R.

Meta

Why/Why not R

Articles

Books and manuals

Tools

Learning R

Classes

Blogs

Packages

Code samples

Libraries

Tech notes, papers and articles on R

Installing R and contributed libraries.

R is made of r-core and thousands of contributed libraries. To begin with, we need to install the core application.

On Linux:

$ sudo apt-get install r-base-core

R and PostgreSQL

Preparing R to query data from postgresql. Reference.

Installation

$ sudo apt-get install libpq-dev
$ sudo apt-get install r-base-core
$ export PG_LIB_DIR=/usr/lib/postgresql/8.4/lib/
$ export PG_INCLUDE_DIR=/usr/include/postgresql

Install R packages from the bash/zsh shell

export CRAN_MIRROR="http://cran.case.edu/"
echo "install.packages(\"rjson\", repos=\"$CRAN_MIRROR\")" | R --vanilla

R Session

source("http://bioconductor.org/biocLite.R")
biocLite("RdbiPgSQL")
library(RdbiPgSQL)
conn <- dbConnect(PgSQL(), host="localhost", dbname="somedb", user="pradeep", password="secret")
res <- dbSendQuery(conn, "SELECT a,b,c from sometable")
mydata <- dbGetResult(res)

R Script

To make a R file into an executable script do the following:

#!/usr/bin/env Rscript

# one.R
# chmod +x one.R
# ./one.R

y=c(12,15,28,17,18)

x=c(22,39,50,25,18)

mean(y)

mean(x)

png(filename="plot.png")
plot(x,y)

Output:

[1] 18
[1] 30.8

and plot.png written to disk.