This vignette covers common issues you may encounter when using dbverse packages and how to resolve them.
library(dbProject)
project_path <- tempfile("dbproject-troubleshooting-")
proj <- dbProject$new(path = project_path)
#> Creating new version '20260504T194458Z-20342'
#> Writing to pin 'cachedConnection'
#> Manifest file written to root folder of board, as `_pins.yaml`
proj$is_connected()
#> [1] TRUE
proj$disconnect()
proj$is_connected()
#> [1] FALSE
unlink(project_path, recursive = TRUE)Error: Could not set lock on file "path/to/database.duckdb":
Conflicting lock is held in /path/to/R (PID 12345) by user...
Cause: DuckDB uses file-level locking to ensure data integrity. Only one process can write to a database file at a time. This error occurs when:
Solutions:
Kill the conflicting process (shown in the error message):
Restart RStudio to close all R processes
Properly disconnect before closing sessions:
Use read-only mode for concurrent access:
Cause: The dbProject connection has been closed or was never established. Solution: Reconnect to the database:
Cause: Lazy table references become stale after R restarts because the connection is lost.
Solution: Use dbProject for automatic reconnection:
# Create project (saves connection info)
proj <- dbProject$new(path = "my_project", dbdir = "data.duckdb")
# After restart, just reload
proj <- dbProject$new(path = "my_project", dbdir = "data.duckdb")
proj$reconnect()
# Pinned objects are automatically reconnected
my_data <- proj$pin_read("my_table")Cause: Accidentally collecting large lazy tables into memory.
Prevention:
Avoid collect() on large tables:
Use pin_write() to materialize intermediates to disk:
Cause: Complex lazy query chains can cause performance issues.
Solution: Use dplyr::compute() or pin_write() to materialize intermediate results:
# Materialize after expensive operations
complex_result <- my_dbMatrix |>
some_expensive_transform() |> # e.g. a function containing several SQL joins
dplyr::compute(name = "materialized", temporary = FALSE)If you encounter issues not covered here: