Skip to content

Commit

Permalink
Cleaner implementation of has_postgres()
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 8, 2016
1 parent 33a9e8c commit 12b910f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions R/src-postgres.r
Expand Up @@ -110,11 +110,15 @@ src_postgres <- function(dbname = NULL, host = NULL, port = NULL, user = NULL,


has_postgres <- function(...) {
ok <- succeeds(src <- src_postgres(...), quiet = TRUE)
if (ok) {
dbDisconnect(src$con)
}
ok
tryCatch(
{
src <- src_postgres(...)
dbDisconnect(src$con)
TRUE
},
error = function(e) {
FALSE
})
}

#' @export
Expand Down

0 comments on commit 12b910f

Please sign in to comment.