Skip to content

R and Postgres

7 messages · Bryce Baril, Sean Davis, Sébastien Bihorel +1 more

#
Hello all,

I'm fairly new to R, and would like to connect to Postgres.

I spent some time trying to figure out how to best do this today, and mostly
found dead-ends and old information.

Could someone please either point me to an active project, perhaps with a
good example on how to do this?

I'm hoping to use a DBI (or DBI-like) interface, but if all else fails I'm
sure I can figure out ODBC.

Thanks,
-Bryce
#
On Tue, Jul 1, 2008 at 3:34 PM, Bryce Baril <bryce at marketoutsider.com> wrote:
Hi, Bryce.  Try:

http://bioconductor.org/packages/2.2/bioc/html/RdbiPgSQL.html

Sean
#
On Tue, 1 Jul 2008 12:34:34 -0700,
"Bryce Baril" <bryce at marketoutsider.com> wrote:

            
The RODBC package comes with good documentation showing this through
ODBC.  Starting with its README helps a lot, and then ?odbcConnect and
the other ?odbc* functions will give you the rest.  I don't know about a
non-ODBC interface between R and PostgreSQL.
#
Hi

I run postgre 8.3 on linux and can access it, ive put a generic example 
of how I got it to work below, ive only used it for a database on a 
local machine.

Hope it gives you a start :)

#########

library(Rdbi)
library(RdbiPgSQL)

#establish connection
conn <- dbConnect(PgSQL(),host='host',dbname='mydatabasename',user='me')

#send query
query <- dbSendQuery(conn,"select * from my table")

#get results
results <- dbGetResult(query)

#close connection
dbDisconnect(conn)

################
Sebastian P. Luque wrote:
#
Excellent, thank you to everyone who helped!

This is what I did to install the packages:

install.packages(c('Rdbi','RdbiPgSQL'), repos="
http://bioconductor.org/packages/1.9/bioc/", dependencies=TRUE)

And then I followed Steve Henshaw's generic example:

On Tue, Jul 1, 2008 at 1:29 PM, Steve Henshaw <steve.henshaw at gmail.com>
wrote:

  
    
#
On Tue, Jul 1, 2008 at 5:25 PM, Bryce Baril <bryce at marketoutsider.com> wrote:
This version is a year+ old.  Your best bet is to do:

source('http://bioconductor.org/biocLite.R')
biocLite('RdbiPgSQL')

This will get you a version that matches your version of R.

Sean
#
On Tue, Jul 1, 2008 at 3:09 PM, Sean Davis <sdavis2 at mail.nih.gov> wrote:

            
Great, thank you.

I had avoided this earlier because (perhaps due to my R newness) I hadn't
seen this syntax before and didn't understand what it was doing as compared
to install.packages().

Thanks,
-Bryce