-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fcad19
commit 5fa8858
Showing
24 changed files
with
665 additions
and
137 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' @rdname SQLiteConnection-class | ||
#' @usage NULL | ||
dbExistsTable_SQLiteConnection_Id <- function(conn, name, ...) { | ||
stopifnot(is(name, "Id")) | ||
|
||
id <- as.list(dbUnquoteIdentifier(conn, dbQuoteIdentifier(conn, name))[[1]]@name) | ||
schema <- id$schema | ||
table <- id$table | ||
|
||
if (!is.null(schema)) { | ||
schemas <- dbGetQuery(conn, "SELECT name FROM pragma_database_list;")$name | ||
|
||
if (!(schema %in% schemas)) { | ||
return(FALSE) | ||
} | ||
} | ||
|
||
sql <- sqliteListTablesQuery(conn, schema, SQL("$name")) | ||
rs <- dbSendQuery(conn, sql) | ||
dbBind(rs, list(name = tolower(table))) | ||
on.exit(dbClearResult(rs), add = TRUE) | ||
|
||
nrow(dbFetch(rs, 1L)) > 0 | ||
} | ||
#' @rdname SQLiteConnection-class | ||
#' @export | ||
setMethod("dbExistsTable", c("SQLiteConnection", "Id"), dbExistsTable_SQLiteConnection_Id) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Standalone file: do not edit by hand | ||
# Source: <https://https://github.com/cynkra/dm/blob/HEAD/R/standalone-check_suggested.R> | ||
# Generated by `usethis::use_standalone("cynkra/dm", "standalone-check_suggested.R", "HEAD", "https://github.com")` | ||
# ---------------------------------------------------------------------- | ||
# | ||
# --- | ||
# repo: cynkra/dm | ||
# file: standalone-check_suggested.R | ||
# last-updated: 2023-02-23 | ||
# license: https://unlicense.org | ||
# imports: rlang, cli, glue | ||
# --- | ||
# | ||
# This file provides a wrapper around `rlang::check_installed()` that skips tests | ||
# and supports optional usage. | ||
# | ||
# Needs functions from rlang, and purrr or standalone-purrr.R. | ||
# | ||
# ## Changelog | ||
# | ||
# 2023-10-19: | ||
# * Initial | ||
|
||
# nocov start | ||
|
||
#' Check if suggested package is installed | ||
#' | ||
#' @param packages Vector of package names to check. Can supply a version | ||
#' between parenthesis. (See examples). | ||
#' @param top_level_fun the name of the top level function called. | ||
#' @param use whether to trigger the check, `NA` means `TRUE` if `is_interactive()` | ||
#' and `FALSE` otherwise | ||
#' @return whether check was triggered and all packages are installed | ||
#' @noRd | ||
#' @examples | ||
#' check_suggested(c("testthat (>= 3.2.0)", "xxx"), "foo") | ||
check_suggested <- function(packages, top_level_fun, use = TRUE) { | ||
# If NA, inform that package isn't installed, but only in interactive mode | ||
only_msg <- is.na(use) | ||
if (only_msg) { | ||
use <- rlang::is_interactive() | ||
} | ||
|
||
if (!use) { | ||
return(FALSE) | ||
} | ||
|
||
# Check installation status if `use` was not `FALSE` | ||
installed <- map_lgl(packages, rlang::is_installed) | ||
|
||
if (all(installed)) { | ||
return(TRUE) | ||
} | ||
|
||
if (only_msg) { | ||
stopc("NYI") | ||
} | ||
|
||
# Skip if some packages are not installed when testing | ||
# And say which package was not installed. | ||
if (identical(Sys.getenv("TESTTHAT"), "true")) { | ||
pkgs_not_installed <- packages[!installed] | ||
message <- "{.fn {top_level_fun}} needs the {.pkg {.val {pkgs_not_installed}}} package{?s}." | ||
testthat::skip(message) | ||
} | ||
|
||
# If in interactive session, a prompt will ask user if they want | ||
# to install the package. | ||
# check_installed() uses pak for installation | ||
# if it's installed on the user system. | ||
|
||
# Which message to display in the prompt | ||
rlang::check_installed(packages, reason = paste0("to use `", top_level_fun, "()`.")) | ||
|
||
# If check_installed() returns, all packages are installed | ||
TRUE | ||
} | ||
|
||
# nocov end |
Oops, something went wrong.