Make sure you have

library(RPostgreSQL)

Read in password if you have it saved in your working directory:

password <- scan(".pgpass", what="")

Or create a prompt to enter it in the Console window:

password <- readline(prompt="Enter password: ")

Create connection object called db. These guides will always use the name db for the connection object. All of the functions that send and receive information from the database will have this as the first argument.

db <- dbConnect(PostgreSQL(), 
                host = "sesync-postgis01.research.sesync.org",
                dbname = "choptank", 
                user = "palmergroup",
                password = password)

If you want to read a whole table from the database into your R environment, you can use dbReadTable().

samplingfeatures <- dbReadTable(db, c("odm2", "samplingfeatures"))
RS-DBI driver warning: (unrecognized PostgreSQL field type uuid (id:2950) in column 1)RS-DBI driver warning: (unrecognized PostgreSQL field type geometry (id:114457131) in column 7)

Disconnect at the end of your session

rr dbDisconnect(db)

LS0tCnRpdGxlOiAiQ29ubmVjdCB0byBjaG9wdGFuay1kYiIKb3V0cHV0OgogIGh0bWxfbm90ZWJvb2s6CiAgaHRtbF9kb2N1bWVudDoKICAgIGRmX3ByaW50OiBwYWdlZAplZGl0b3Jfb3B0aW9uczoKICBjaHVua19vdXRwdXRfdHlwZTogaW5saW5lCi0tLQoKYGBge3Igc2V0dXAsIGluY2x1ZGU9RkFMU0UsIG1lc3NhZ2U9RkFMU0V9CmtuaXRyOjpvcHRzX2NodW5rJHNldChlY2hvID0gVFJVRSkKbGlicmFyeShrbml0cikKbGlicmFyeShtYWdyaXR0cikKYGBgCgpNYWtlIHN1cmUgeW91IGhhdmUKCiogaW5zdGFsbGVkIHRoZSBgUlBvc3RncmVTUUxgIGxpYnJhcnkgd2l0aCBgaW5zdGFsbC5wYWNrYWdlcygiUlBvc3RncmVTUUwiKWAuCiogc2F2ZWQgdGhlIGRhdGFiYXNlIHBhc3N3b3JkIGFzIGAucGdwYXNzYCBpbiB5b3VyIHdvcmtpbmcgZGlyZWN0b3J5LgoqIGNvbm5lY3RlZCB0byBWUE4gb3IgYXJlIHVzaW5nIHJzdHVkaW8uc2VzeW5jLm9yZwoKYGBge3IsIG1lc3NhZ2U9RkFMU0V9CmxpY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