Skip to contents

Returns the database path to use, by order of precedence: an R option, an environment variable, then a default. Projects set the default in their paths_and_packages.R; the option or the environment variable point a run to a copy of the database (to test a change, or to read while a collection holds the lock) without editing any script.

Usage

resolve_db_path(default, env_var = NULL, option = NULL)

Arguments

default

Character. The path used when neither the option nor the environment variable is set.

env_var

Character or NULL. Name of an environment variable (e.g. "CB_DUCKDB").

option

Character or NULL. Name of an R option (e.g. "cb.db_path").

Value

The path, with ~ expanded.

Examples

resolve_db_path("~/data/project/project.duckdb", env_var = "PROJECT_DUCKDB")
#> [1] "/home/agoutsmedt/data/project/project.duckdb"

withr::with_options(
  list(project.db_path = "/tmp/copy.duckdb"),
  resolve_db_path("~/data/project/project.duckdb", option = "project.db_path")
)
#> [1] "/tmp/copy.duckdb"