Last active
March 15, 2020 17:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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