dbpf_con | R Documentation |
Returns connection to permafrost database
dbpf_con(user, passwd, host, port = "5432", database = "observations")
user |
character, User name |
passwd |
character, Password |
host |
character, Location of database server, This is usually an IP address or a URL. |
port |
character, port on which to make request. Typically "5432" for postgres databases. |
database |
character, "observations" or for testDB:"obs_dev" |
Function establishes a connection to the data base and returns a connection object for easy use. When finished, make sure to close the connection object (see examples).
As of PermafrostDB v1.0.0
, Database credentials and host location must now be explicitly provided.
Default connection information is no longer provided. This is done as a
security consideration. However, to retain the convenience of older version of this function,
you can create a text file called permafrostdb.config
that provides the
necessary information.
The location of the permafrostdb.config
file is determined by the R function path.expand("~")
.
On linux computers, this usually corresponds to /home/username
. On Windows machines, this is usually either
C:/Users/yourUserName
or C:/Users/yourUserName/Documents
(RStudio). To be sure, run the command
path.expand("~")
in your R terminal of choice.
The file should be structured like a csv table, and should use quotes around the parameters:
user,passwd,host,port
"your_username","your_pasword","your_db_host","your_db_port"
an example might look like:
user,passwd,host,port
"readonly","fjZ$fwg?H9(<jDsd","256.245.11.15","5432"
Returns a DB connection object.
Stephan Gruber <stephan.gruber@carleton.ca>
#example of using specific user name and password
## Not run:
con <- dbpf_con("stephan", "password", "192.168.2.25", "5432")
dbDisconnect(con)
# get connection object (using default values from a permafrostdb.config file)
con <- dbpf_con()
loc <- dbGetQuery(con, "SELECT * FROM locations")
dbDisconnect(con) # close connection when done
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.