rpgconn

rpgconn is a PostgreSQL connection management package for R.

It gives you one stable interface (dbc()) for:

The package is designed to fail fast with explicit errors before DBI tries to connect.

Installation

# 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'))

Quick Start

1. Connect from 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)

2. Connect from YAML config

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

3. Use project-specific config files

cn <- dbc(
  cfg = "dev",
  db = "analytics",
  cfg_path = "config/dev-db.yml",
  opt_path = "config/dev-options.yml"
)
dbd(cn)

Main API

Notes:

Connection String Formats

dbc() accepts:

Documentation (Pkgdown + Quarto)

This repo uses:

Primary long-form docs:

Build docs locally:

devtools::document()
pkgdown::build_site()

Development Setup

Install all development dependencies declared in DESCRIPTION:

pak::local_install_dev_deps(dependencies = TRUE)

Daily workflow:

devtools::load_all()
devtools::test()
devtools::check()

Testing Strategy

Unit tests

Unit tests are hermetic:

Optional local Postgres E2E test

A 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.

Release Workflow

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:

Maintainer Conventions

Project Layout

Links