Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. library(RPostgreSQL)
  2.  
  3.  
  4. # create a connection
  5. # save the password
  6. pw <- "password"
  7. # alteratively, store in an external file.
  8. ps <- readline(file('password.txt', open = 'r'))
  9.  
  10. # loads the PostgreSQL driver
  11. drv <- dbDriver("PostgreSQL")
  12. # creates a connection to the postgres database
  13. # note that "con" will be used later in each connection to the database
  14. con <- dbConnect(drv, dbname = "cake",
  15. host = "localhost", port = 5432,
  16. user = "username", password = pw)
  17. rm(pw) # removes the password
  18.  
  19. # check for the cartable
  20. dbExistsTable(con, "table_name")
  21. # TRUE
  22.  
  23. data <- dbReadTable(con, 'table_name')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement