Alex Rivera | Logout

Importing files from PostgreSQL to R

Asked 2012-09-19T08:17:51.150
14

I have a large data-set and I will preform some analysis in R software. While I could not import the data properly to R.

I get this error:

Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect User@local on dbname "Intel"

I have used PostgreSQL to open data and somehow manage it. How can I import the existing data in the PostgreSQL to the R software?

Edit
Report

1 Answer

7

Try the R package RPostgreSQL http://cran.r-project.org/web/packages/RPostgreSQL/ . You can see how to use it in http://code.google.com/p/rpostgresql/ . Example:

library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")   ## loads the PostgreSQL driver
con <- dbConnect(drv, dbname="R_Project")   ## Open a connection 
rs <- dbSendQuery(con, "select * from R_Users")   ## Submits a statement
fetch(rs,n=-1)   ## fetch all elements from the result set
dbGetQuery(con, "select * from R_packages")   ## Submit and execute the query
dbDisconnect(con)   ## Closes the connection
dbUnloadDriver(drv)   # Frees all the resources on the driver
answered 2012-09-19T08:31:31.093

Your Answer