db_tables_to_list: Make a named list of 'tbl_dbi' objects from a 'DBIConnection'...

View source: R/utils.R

db_tables_to_listR Documentation

Make a named list of tbl_dbi objects from a DBIConnection object

Description

A convenience function that returns a list of tbl_dbi objects from a DBIConnection object, named as per the database table names.

Usage

db_tables_to_list(conn)

Arguments

conn

A DBIConnection object, as returned by dbConnect.

Details

See the introduction to dbplyr vignette for getting started with databases and dplyr.

Value

A named list of tbl_dbi objects

Examples

# create an SQLite database in memory
con <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:")

# populate with tables
dplyr::copy_to(con, head(iris), "iris_head")
dplyr::copy_to(con, head(mtcars), "mtcars_head")

# create named list of tbl_dbi objects
db_tables <- db_tables_to_list(con)

# view tables
db_tables$iris_head
db_tables$mtcars_head

# to import to R, use dplyr::collect()
dplyr::collect(db_tables$iris_head)

rmgpanw/ukbwranglr documentation built on April 30, 2024, 7:47 a.m.