R/TxDbLite.R

Defines functions TxDbLite

Documented in TxDbLite

#' Create a TxDbLite object (usually called by subclass constructors)
#' 
#' @param x an annotation instance of TxDbLite 
#' @param path  where it lives (default: ".")
#' @param ...   additional parameters 
#' @return   a TxDbLite object 
#' @importFrom DBI dbDriver dbConnect dbListTables dbGetQuery
#' @export
TxDbLite <- function(x, path=".", ...) { 
  options(useFancyQuotes = FALSE)
  if (!grepl(".sqlite$", x)) x <- paste0(x, ".sqlite")
  x <- paste(path, x, sep=.Platform$file.sep)
  lite <- dbDriver("SQLite")
  con <- dbConnect(lite, dbname = x, flags = SQLITE_RO)
  tables <- dbListTables(con)
  names(tables) <- tables
  Tables <- lapply(tables, function(x) 
    colnames(dbGetQuery(con, paste0("select * from ", x, " limit 1"))))
  new("TxDbLite", con = con, tables = Tables)
}
arcolombo/TxDbLite documentation built on July 10, 2020, 12:27 a.m.