R database attach
- R 100%
|
|
||
|---|---|---|
| man | masstodon driven dev | |
| R | masstodon driven dev | |
| DESCRIPTION | masstodon driven dev | |
| NAMESPACE | masstodon driven dev | |
| README.md | better readme | |
dbat
Simple package with one function, dbat that takes a DBI connection object
and makes all tables and views from the connection visible on the
search path. It uses R's makeActiveBinding function so that the data
is only loaded when the R object is fetched, which is very inefficient
for large data used multiple times.
Examples:
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "db_mtcars", mtcars)
dbat(con)
At this point, db_mtcars is an R object that is on
the search path (probably position 2, as "e", which I
should make nicer)
search()
ls(pos=2)
head(db_mtcars)
If you want to do lots of things with this data frame then you probably want to read it into memory once to your global environment.
my_db_mtcars = db_mtcars
Disconnecting the database connection breaks the object, but your copy in your global environment is fine. I should make this clean up better.
DBI::dbDisconnect(con)
### with the connection closed, this then breaks...
head(db_mtcars)
Install it:
devtools::install_git(url ="https://codeberg.org/browlingson/dbat/")