RPostgres examples and tests connect to a default database via dbConnect(Postgres()). This function checks if that database is available, and if not, displays an informative message.

postgresDefault() works similarly but returns a connection on success and throws a testthat skip condition on failure, making it suitable for use in tests.





Additional arguments passed on to dbConnect()


if (postgresHasDefault()) { db <- postgresDefault() dbListTables(db) dbDisconnect(db) }
#> Could not initialise default postgres database. If postgres is running #> check that the environment variables PGHOST, PGPORT, #> PGUSER, PGPASSWORD, and PGDATABASE, are defined and #> point to your database.