Skip to content

Instantly share code, notes, and snippets.

@chasemc
Last active March 15, 2020 17:02
Show Gist options
  • Save chasemc/0d8f864b843dd06f8f7957123cf4cd8c to your computer and use it in GitHub Desktop.
Save chasemc/0d8f864b843dd06f8f7957123cf4cd8c to your computer and use it in GitHub Desktop.
Two functions: Check if an object is pool; Get path of database from pool
#' Check if a pool object
#'
#' @param pool variable to check
.checkPool <- function(pool){
val <- all(inherits(pool, "Pool"),
inherits(pool, "R6"))
if (isFALSE(val)) {
# paste0(deparse(sys.calls()[[sys.nframe()-1]]) gets the info of the calling function
stop(paste0(deparse(sys.calls()[[sys.nframe() - 1]]),
" expected a pool object"))
}
}
#' Find database path from pool object
#'
#' @param pool {pool} object
#'
#' @return Path to pool's database
.db_path_from_pool <- function(pool){
.checkPool(pool = pool)
provided_db_path <- normalizePath(pool$fetch()@dbname,
winslash = "/")
if (file.exists(provided_db_path)) {
return(provided_db_path)
} else {
stop("\n",
"Couldn't find:",
"\n",
provided_db_path)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment