[R] R and Postgresql (DBI)

Dirk Eddelbuettel edd at debian.org
Fri Jan 9 02:13:04 CET 2004

On Thu, Jan 08, 2004 at 04:24:17PM -0800, Ian Garcia wrote:
>  I'm running Debian (Sid), Postgres (7.3.4) and
>  R (1.8.1).
>  I get the following error when I tri to use DBI
>  >library("DBI")
>  > p <- dbDriver("PostgreSQL") 
>  Error in do.call(as.character(drvName), list(...)) :
>         couldn't find function "PostgreSQL"
>  Is there any other package I need in order to
>  interface between R and Postgres ?

No, you simply can't do that. 

Long answer: that doesn't even work as the R DBI infrastructure still lacks a 
a Postgres connector package (like the existing one for SQLite, Oracle, ...).

However, the BioConductor project has two packages that provide a parallel
track to DBI -- called Rdbi, confusingly enough -- as well as its connector
package RdbiPgSQL to connect via Rdbi to Postgresql.  You find them at
www.bioconductor.org in source form.

Alternatively, you can use the CRAN RODBC package along with the Postgres
ODBC package -- and a quick
	$ apt-get install r-cran-rodbc odbc-postgresql 
should get them installed for you.  This needs a little bit of configuration
in /etc/odbcinst.ini:

edd at homebud:~/debian> cat /etc/odbcinst.ini
Description     = PostgreSQL ODBC driver for Linux and Windows
#Driver         = /usr/lib/postgresql/lib/libodbcpsql.so
#Setup          = /usr/lib/odbc/libodbcpsqlS.so
Driver          = /usr/lib/postgresql/lib/psqlodbc.so
Setup           = /usr/lib/odbc/libodbcpsqlS.so
Debug           = 0
CommLog         = 1

as well as a DSN definition, either in /etc/odbc.ini or in $HOME:
edd at homebud:~/debian> cat ~/.odbc.ini
[ODBC Data Sources]
foo = Foo Database
bar = Bar Database

Driver       = /usr/lib/postgresql/lib/psqlodbc.so
Database     = foo
Servername   = localhost
ReadOnly     = 0

Driver       = /usr/lib/libmyodbc.so
Database     = bar
Servername   = localhost
ReadOnly     = 0

Driver       = /usr/lib/postgresql/lib/psqlodbc.so
Database     = dbd_odbc_test_db
ReadOnly     = 0
Servername   = localhost

InstallDir = /usr/lib

Let me know in private mail if you need more help.

Hth, Dirk

The relationship between the computed price and reality is as yet unknown.  
                                             -- From the pac(8) manual page

More information about the R-help mailing list