-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgres.R
40 lines (31 loc) · 966 Bytes
/
postgres.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
pacman::p_load(tidyverse,
glue,
janitor,
sf,
DBI,
RPostgres,
config)
creds <- config::get()
tryCatch({
# drv <- dbDriver("PostgreSQL")
print("Connecting to Database…")
connec <- dbConnect(drv = RPostgres::Postgres(),
dbname = creds$database,
host = creds$host,
port = creds$port,
user = creds$user,
password = creds$pass)
print("Database Connected!")
},
error=function(cond) {
print("Unable to connect to Database.")
})
dbListObjects(connec, prefix = Id(schema = 'brerc'))
dbListFields(connec,
name = Id(schema = "brerc",
table = "habitat_map"))
dbListTables(connec, "brerc")
habmap_tbl <- tbl(connec, dbplyr::in_schema(schema = 'brerc', table = 'habitat_map')) %>%
head(100) %>%
collect()
dbDisconnect(connec)