#' Create a tbl pointer to any CDW database/schema/table
#'
#' If a name is not provided, will print a list of the available tables in the current connection settings.
#'
#' @param conn a DBI-compliant connection object. recommend using the 'connect_cdw()` function
#' @param name A character string specifying the table name
#'
#' @return a tbl or a display of tables and views available
#'
#' @importFrom dplyr tbl
#' @importFrom dbplyr in_schema sql
#' @importFrom DBI dbListTables
#'
#' @export
#'
#' @examples
#'
#' \dontrun{
#' conn <- connect_cdw()
#'
#' cdw_tbl(conn)
#'
#' cdw_tbl(conn, DBI::Id(database = "CLINICAL_ANALYTICS_PROD",
#' schema = "DMS_ACUTE_CARE",
#' table = "SEPSIS"))
#'
#' disconnect_cdw(conn)
#'}
cdw_tbl <- function(conn, name = NA) {
# Todo: check that there's a valid connection
if(!is.na(name)) {
dplyr::tbl(conn, name)
#dplyr::tbl(conn, DBI::Id(database = database, schema = schema, table = name))
}
else {
cat("Table not specified.\nHere's a list of available tables with the current settings:\n\n")
results <- DBI::dbListTables(conn)
results
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.