## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----project-demo-------------------------------------------------------------
library(dbProject)

project_path <- tempfile("dbproject-")
proj <- dbProject$new(path = project_path)
expression_data <- data.frame(gene = c("A", "B"), count = c(10, 20))
proj$pin_write(expression_data, "expression_data")

# Later (even after R restart):
proj$reconnect()
my_tbl <- proj$pin_read("expression_data")
my_tbl

## ----dbi-list-tables----------------------------------------------------------
con <- proj$get_conn()
DBI::dbWriteTable(
  con,
  "sample_metadata",
  data.frame(sample = c("sample1", "sample2"), n = c(100, 120)),
  overwrite = TRUE
)
DBI::dbExecute(
  con,
  "CREATE OR REPLACE TEMPORARY TABLE current_batch AS
   SELECT * FROM sample_metadata"
)
DBI::dbExecute(
  con,
  "CREATE OR REPLACE VIEW sample_summary AS
   SELECT sample, n FROM sample_metadata"
)

DBI::dbListTables(con)

## ----dbproject-list-tables----------------------------------------------------
dbList(con)

## ----cleanup, include=FALSE---------------------------------------------------
proj$disconnect()
unlink(project_path, recursive = TRUE)

