Description Usage Arguments Details Value Warning Examples
Creates a connection object that can be used to connect to a
specific database an a PostgreSQL database server. This function
requires that connection credentials including username
and
password
be stored in your .Renviron
file. It will
not be able to locate your connection credentials otherwise.
1 | pg_con(host_label, dbname, user_label, pw_label, port = "5432")
|
host_label |
a string label to identify the server host |
dbname |
a database on a PostgreSQL server |
user_label |
a string label to identify the server username |
pw_label |
a string label to identify the server password |
port |
a port string used to connect to the database |
See the Readme file at https://github.com/arestrom/repg for
details on how to set up your .Renviron
file. The string labels for
host_label, user_label, pw_label
are needed to locate your
connection credentials in your .Renviron
file.
A connection object to a database located on a PostgreSQL server
Remember to close your connection after you are done. See example below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## Not run:
# Create a connection object to a PostgreSQL database on localhost
db_con_local = pg_con(
host_label = "my_pg_host_local",
dbname = "sport_sampling",
user_label = "my_pg_username_local",
pw_label = "my_pg_password_local",
port = "5432")
# Connect to database and retrive a count of records in a table
tbl_count = DBI::dbGetQuery(db_con_local,
"select count(*) from survey_type_lut")
DBI::dbDisconnect(db_con_local)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.