R pgsql

R and PostgreSQL

Adapted from http://grass.itc.it/statsgrass/r_and_dbms.html

Installation

> rS="http://www.bioconductor.org/packages/2.0/bioc/"
> install.packages("Rdbi", repos=rS)
> install.packages("RdbiPgSQL", repos=rS,configure.args= c(PGSQL =  '--with-pgsql-libraries=/usr/local/pgsql/lib --with-pgsql-includes=/usr/local/pgsql/include'))

R needs to load libpq.so, so /etc/ld.so.conf should contains /usr/local/pgsql/lib !

Playing

                                   
> conn <- dbConnect(PgSQL(), host="localhost", dbname="cas", user="megera")
> snquery = dbSendQuery(conn, "select * from sn.sn")
> sn = dbGetResult(snquery)
> str(sn)

Now, sn$id contains id's of sn, sn$type - numerical sn type, etc.

See distribution of SNe on sky

> plot(sn$ra,sn$dec)

The same, but for Ib (3),Ib/c(4) types

> plot(sn$ra[sn$type %in% c(3,4)],sn$dec[sn$type %in% c(3,4)])