This is the R client package for the Databrary API — a CRAN-published wrapper (install.packages("databraryr")) for building reproducible data-wrangling, analysis, and visualization pipelines against data stored on Databrary. It is a standalone R package (not part of the databrary-core ecosystem) and the R sibling of databrarypy. Built on httr2, with OAuth2 auth, retry, pagination, and binary/zip downloads, exposing functions for volumes, sessions, folders, records, assets, users, institutions, search, uploads, and bulk operations.
- R >= 4.3.2; lifecycle: stable; version
1.0.0.9000(dev). - Upstream repo:
https://github.com/databrary/databraryr; site:https://databrary.github.io/databraryr/.
databraryr/
├── R/ # All package source (one concern per file)
│ ├── make_default_request.R # httr2 request builder: base URL, user agent, retry, timeout, auth header
│ ├── make_login_client.R, login_db.R, logout_db.R, whoami.R # Session entry points
│ ├── auth_service.R, auth_state.R, auth_utils.R, token_helpers.R # OAuth2 + token cache/refresh
│ ├── CONSTANTS.R, misc_enums.R, assign_constants.R, aaa.R, zzz.R # Constants, enums, onLoad
│ ├── api_utils.R, download_utils.R, upload_utils.R, utils.R, utils-pipe.R # Shared helpers
│ ├── list_*.R / get_*.R / search_*.R # Read endpoints
│ ├── create_*.R / update_*.R / patch_*.R / delete_*.R / set_*.R # Write endpoints
│ ├── download_*.R / upload_file.R / initiate_upload.R / complete_upload.R # Asset transfer
│ └── bulk_*.R # Bulk create/delete/rename/assign + resume support
├── man/ # roxygen2-GENERATED .Rd help — do not edit by hand
├── tests/testthat/ # testthat (edition 3) tests, one test-*.R per R/ source + helpers
├── vignettes/ # Long-form guides: databrary, accessing-data, authorized-users
├── DESCRIPTION # Package metadata, deps, version, authors
├── NAMESPACE # roxygen2-GENERATED exports/imports — do not edit by hand
├── NEWS.md # Changelog (hand-maintained)
├── README.Rmd / README.md # README.md is GENERATED from README.Rmd — edit the .Rmd
├── _pkgdown.yml, pkgdown/ # pkgdown site config
├── .lintr # lintr config (120-char lines; exclusions for _wip, tests, CONSTANTS)
├── .Renviron # Local API credentials/host (gitignored values; do not commit secrets)
└── .Rprofile # Dev convenience: auto runs devtools::document() + load_all() on open
- Requests: every call starts from
make_default_request()(inmake_default_request.R), which builds anhttr2request with the base URL (DATABRARY_BASE_URL),USER_AGENT,Accept: application/json, retry (RETRY_LIMIT), and timeout (REQUEST_TIMEOUT). By default it attaches an OAuth2Authorizationheader and refreshes the token if near expiry. - Auth/token state:
login_db()performs the OAuth2 password grant; the token bundle (access/refresh tokens, expiry, client id/secret, username) is cached in a package-private environment (auth_state.R) and can optionally be persisted via keyring (login_db(store = TRUE)).token_helpers.R/auth_service.Rhandle refresh. - Config: credentials and host come from environment variables read from
.Renviron—DATABRARY_CLIENT_ID,DATABRARY_CLIENT_SECRET,DATABRARY_LOGIN, optionalDATABRARY_PASSWORD(else prompted via getPass), and optionalDATABRARY_BASE_URL(defaults tohttps://api.databrary.org; point at staging here). Package options are managed via the options package. - Endpoints: each public function lives in its own
R/file with a paralleltests/testthat/test-*.R. Functions return tibbles/lists; downloads write to disk or return raw content.
Generated files
- DON'T hand-edit
NAMESPACEor anything inman/— both are generated by roxygen2. Edit the roxygen comments above the function inR/and rundevtools::document()(the.Rprofiledoes this on session start). - DON'T edit
README.mddirectly — editREADME.Rmdand re-knit. The header says so explicitly.
Adding/changing endpoints
- DO add each new endpoint as its own
R/<verb>_<noun>.Rfile, following the existing naming (list_*,get_*,search_*,create_*,update_*,patch_*,delete_*,bulk_*). - DO build requests via
make_default_request()rather than constructinghttr2::request()from scratch, so auth, retry, user-agent, and timeout stay consistent. - DO add a matching
tests/testthat/test-<name>.Rand@export+ roxygen docs (with@examples) for any user-facing function.
Auth & secrets
- DON'T manage tokens ad hoc in endpoint functions — token caching/refresh lives in
auth_state.R/token_helpers.R/auth_service.R. - DON'T commit credentials. Real values belong in a developer's own
.Renviron/keyring, never in tracked files. Tests requiring live auth should skip gracefully when credentials are absent.
Conventions
- DO keep lines within the lintr limit (120 chars) and respect
.lintrexclusions; new constants generally go inCONSTANTS.R. - DO update
NEWS.mdfor user-visible changes, and bumpVersioninDESCRIPTIONper CRAN/semver conventions when releasing. - DO keep vignettes runnable (they gate on credentials/network — guard live calls).
Standard R-package workflow (devtools/testthat; no Makefile):
devtools::document() # regenerate man/ and NAMESPACE from roxygen comments
devtools::load_all() # load the package for interactive work
devtools::test() # run testthat suite (edition 3)
devtools::check() # full R CMD check (what R-CMD-check.yaml runs)
lintr::lint_package() # style/lint per .lintr (matches lint.yaml)
covr::package_coverage() # coverage (matches test-coverage.yaml)
pkgdown::build_site() # build docs site (matches pkgdown.yaml)CI workflows in .github/workflows/: R-CMD-check.yaml (build/check), lint.yaml (lintr), test-coverage.yaml (covr), pkgdown.yaml (docs site). Many tests touch the live API and skip without valid credentials/network — keep that guarding intact.
- README.Rmd — install, credentials setup (
.Renvironvars),login_db()/whoami()quickstart - vignettes/ —
databrary(intro),accessing-data,authorized-users - DESCRIPTION — dependencies, version, maintainers
- NEWS.md — changelog
- Package site:
https://databrary.github.io/databraryr/ - databrarypy — the sibling Python client for the same API
- Databrary API:
https://api.databrary.org(override viaDATABRARY_BASE_URL)