First install the following.  (On Windows they all have automated installers.)

- java runtime environment (JRE)
  http://java.sun.com 
  (Don't need larger java development environment.)

- postgresql
  http://www.postgresql.org
  *** Note that certain antivirus programs conflict with PostgreSQL. ***

- postgresql JDBC driver.  You will be asked if you want to install extra
  software (known as a stack) when you install postgresql.  Be sure to indicate
  you do want the stack and then be sure to tell it that you want to install
  JDBC when asked.

After installing RpgSQL you must ensure that it can find the JDBC .jar file.
This is the only file it needs to know the whereabouts of.  It will search
the following locations for postgres*.jdbc4.jar and if not found for
postgres*.jar so ensure that its in one of the following places:

  - the path/filename defined by the global R option RpgSQL.JAR
  - the path/filename defined by the environment variable RpgSQL_JAR
  - the current directory
  - the paths defined by the CLASSPATH system environment variable if it exists
  - the system path 
  - /usr/local/pgsql/share/java (non-Windows only)
  - /opt/local/share/java (non-Windows only)
  - %PROGRAMFILES%\PostgreSQL\pgJDBC (Windows only)

Alternately the R option RpgSQL.JAR or system environment variable RpgSQL_JAR
may specify the entire path and filename in which case it will use that rather
than do a search.

For example, if the JDBC driver jar file for PostgreSQL is in your home
directory, you could put this into your ~/.Rprofile file (or on Windows
%HOME%\.Rprofile where HOME defaults to %userprofile%\Documents): 

	options(RpgSQL.JAR = "~/postgresql-8.4-701.jdbc4.jar")

Also the default user, password and dbname are "postgresql", "" and "test". To
specify anything add to the same file these lines:

	options(RpgSQL.user = "myname")
	options(RpgSQL.password = "mypassword")
	options(RpgSQL.dbname = "mydbname")

(That is there are up to 4 lines in all to add to your .Rprofile file.)

In the following examples the settings that we specified are the defaults 
so they could have been omitted.

The options statements could be placed in the .Rprofile file after which R
should be restarted.

EXAMPLE 1.

library(RpgSQL)
options(RpgSQL.JAR = "C:\\Program Files\\PostgreSQL\\pgJDBC")
con <- dbConnect(pgSQL(), user = "postgresql", password = "", dbname = "test",
	host = "localhost", port = 5432)
dbListTables(con)
dbDisconect(con)

EXAMPLE 2.

library(RpgSQL)
options(RpgSQL.JAR = "C:\\Program Files\\PostgreSQL\\pgJDBC",
  RpgSQL.user = "postgresql", 
  RpgSQL.password = "", 
  RpgSQL.dbname = "test",
  RpgSQL.hostname = "localhost", 
  RpgSQL.port = 5432)
con <- dbConnect(pgSQL())
dbListTables(con)
dbDisconnect(con)

