#' performs a database query
#'
#' performs a database query
#' @param db is the database name
#' @param x is the string representing a SQL query
#' @keywords query
#' @export
#' @examples
#' query(olap, "select * from question_answer limit 6")
query <- function(db, x){
require(data.table)
cat(x, "\n")
t0 = Sys.time()
h = do.call(db, list())
x = data.table(dbGetQuery(h, x))
dbDisconnect(h)
for (j in grep('_seq$', names(x), value=T)) set(x, j = j, value = as.integer(x[[j]]))
duration = difftime(Sys.time(), t0)
uni = attr(duration, "units")
duration = round(as.numeric(duration), 2)
cat("query completed in", duration, uni, "\n")
x
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.