rpgconn is a PostgreSQL connection management package for R.
It gives you one stable interface (dbc()) for:
RPG_CONN_STRING environment-variable connectionscfg = "dev")cfg_path, opt_path)The package is designed to fail fast with explicit errors before DBI tries to connect.
# CRAN
install.packages("rpgconn")
# Development
# pak::pkg_install("r-data-science/rpgconn")
install.packages("rpgconn", repos = c('https://r-data-science.r-universe.dev', 'https://cloud.r-project.org'))
RPG_CONN_STRING
library(rpgconn)
Sys.setenv(
RPG_CONN_STRING = "postgresql://user:pass@localhost:5432/mydb?sslmode=require"
)
cn <- dbc()
DBI::dbGetQuery(cn, "SELECT version()")
dbd(cn)
library(rpgconn)
init_yamls() # creates config + options in tools::R_user_dir("rpgconn", "config")
edit_config() # edit config.yml
cn <- dbc(cfg = "dev", db = "analytics")
dbd(cn)
Example config.yml:
config:
dev:
host: localhost
port: 5432
user: app_user
password: secret
cn <- dbc(
cfg = "dev",
db = "analytics",
cfg_path = "config/dev-db.yml",
opt_path = "config/dev-options.yml"
)
dbd(cn)
dbc(): build connection args or open a PostgreSQL connectiondbd(): disconnectinit_yamls(): create default config + options filesedit_config(), edit_options(): open active files interactivelyuse_config(): replace active config with an external YAML fileNotes:
dbc(path = ...) is supported for backward compatibility but deprecated; use cfg_path.dbc() accepts:
postgresql://user:pass@host:5432/db?sslmode=require
postgres://...
host=...;port=...;dbname=...
host=... port=... dbname=...
This repo uses:
R/*.R -> man/*.Rd)vignettes/*.qmd)Primary long-form docs:
vignettes/quickstart.qmdvignettes/rpgconn.qmdvignettes/advanced-workflow.qmdBuild docs locally:
devtools::document()
pkgdown::build_site()
Install all development dependencies declared in DESCRIPTION:
pak::local_install_dev_deps(dependencies = TRUE)
Daily workflow:
devtools::load_all()
devtools::test()
devtools::check()
Unit tests are hermetic:
R_USER_CONFIG_DIR to temp directoriesRPG_CONN_STRING per test~/.config filesA disposable integration test is included and skipped by default.
Enable locally:
export RPGCONN_RUN_DB_TESTS=true
export RPGCONN_TEST_CONN_STRING="postgresql://postgres:postgres@localhost:5432/postgres"
Then run:
devtools::test()
The E2E test uses a temporary table (CREATE TEMP TABLE) so test data is removed automatically when the connection closes.
Run the full pre-release gate:
devtools::document()
devtools::test()
devtools::check()
devtools::spell_check()
urlchecker::url_check(".")
If Quarto cache permissions cause attempt to write a readonly database, run:
withr::with_envvar(c(XDG_CACHE_HOME = tempdir()), devtools::check())
Then:
NEWS.md
cran-comments.md
data.table semantics whenever tabular manipulation is needed..qmd format.R/: package sourcetests/testthat/: unit + optional E2E testsvignettes/: Quarto documentation_pkgdown.yml: site configuration.github/workflows/: CI for checks, coverage, pkgdown deployAGENTS.md: persistent AI/automation conventions for this repo