Created
May 23, 2014 22:13
-
-
Save 00krishna/19313e7dcdfde73fcbd5 to your computer and use it in GitHub Desktop.
connect to postgresql database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import Libraries | |
library(RPostgreSQL) | |
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
#' Connect to PostgreSQL database | |
#' | |
#' This takes a database name and then connects to it. | |
#' @param dname The name of the database that houses the dlhs data | |
#' @return a database connection object to the specified database | |
#' @author krishna bhogaonker, apr 2014 | |
#' @export | |
db_conn <- function(dname) { | |
drv <- dbDriver("PostgreSQL") | |
# make a connection | |
tryCatch({ | |
con <- dbConnect(drv,dbname=dname)}, | |
error=function(e) {stop(conditionMessage(e), " error connecting to the database, check that the name is correct") | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment