con_db: Makes a connection to a database.

Description Usage Arguments Details Value Examples

Description

Creates a connection to a database. This function is really a high-level function that calls the corresponding con_db function for a particular database driver.

Usage

1
2
3
con_db(dbname = Sys.getenv("LOGNAME"), user = Sys.getenv("LOGNAME"),
  driver = "PostgreSQL", host = "postgresql", port = 5432,
  close_existing_cons = TRUE, pass = NULL)

Arguments

dbname

the name of the database you want to connect to, defaults to current user

user

the username for the database connection, defaults to current user

driver

the database driver to use, defaults to 'PostgreSQL'

host

where the database is running, defaults to 'postgresql (the docker container name)'

port

the port where the database in running, defaults to '5432' for PostgreSQL

close_existing_cons

whether to close existing database connections, defaults to 'TRUE'. You need to set this to FALSE if you are planning to make simultaneous database connections.

pass

optional, defaults to NULL. If .dbpass exists in users home directory, password will be read from file (not advised). It will then try to run the 'sdalr::get_my_password()' function, if that fails it will prompt the user for a password. You can also directly pass in a password as a string (not advised).

Details

Best way to use this function is to make sure your username and passwords are stored safely. You can do this by running 'sdalr::setup_user_pass' (if you mistyped your password run 'sdalr::update_user_pass“).

Value

database connection

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
con_db('sample_db', 'dan', 'isawesome')

## End(Not run)
## Not run: 
con <- sdalr::con_db(dbname = 'arlington', user = 'chend')
df <- DBI::dbGetQuery(con, "SELECT * FROM fire.medic_unit_movement_summary_2013")
head(df)

## End(Not run)

bi-sdal/sdalr documentation built on May 12, 2019, 8:29 p.m.