From bf2886e1d7d52110a1ab1db38700651a92d484e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 11 Oct 2023 22:08:14 +0200 Subject: [PATCH] chore: Fix tests when dplyr is missing --- R/backend-dbplyr__duckdb_connection.R | 2 +- man/backend-duckdb.Rd | 2 ++ tests/testthat/test_tbl__duckdb_connection.R | 12 +++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/R/backend-dbplyr__duckdb_connection.R b/R/backend-dbplyr__duckdb_connection.R index 4dda1aa96..c27f03f6f 100644 --- a/R/backend-dbplyr__duckdb_connection.R +++ b/R/backend-dbplyr__duckdb_connection.R @@ -7,7 +7,7 @@ #' #' @name backend-duckdb #' @aliases NULL -#' @examples +#' @examplesIf rlang::is_installed("dbplyr") #' library(dplyr, warn.conflicts = FALSE) #' con <- DBI::dbConnect(duckdb(), path = ":memory:") #' diff --git a/man/backend-duckdb.Rd b/man/backend-duckdb.Rd index cdac292c0..3eab99358 100644 --- a/man/backend-duckdb.Rd +++ b/man/backend-duckdb.Rd @@ -18,6 +18,7 @@ possibilities. This mainly follows the backend for PostgreSQL, but contains more mapped functions. } \examples{ +\dontshow{if (rlang::is_installed("dbplyr")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr, warn.conflicts = FALSE) con <- DBI::dbConnect(duckdb(), path = ":memory:") @@ -29,4 +30,5 @@ dbiris \%>\% head(5) DBI::dbDisconnect(con, shutdown = TRUE) +\dontshow{\}) # examplesIf} } diff --git a/tests/testthat/test_tbl__duckdb_connection.R b/tests/testthat/test_tbl__duckdb_connection.R index f0bb07d82..bc5607e35 100644 --- a/tests/testthat/test_tbl__duckdb_connection.R +++ b/tests/testthat/test_tbl__duckdb_connection.R @@ -2,6 +2,8 @@ skip_on_cran() `%>%` <- dplyr::`%>%` test_that("Parquet files can be registered with dplyr::tbl()", { + skip_if_not_installed("dplyr") + con <- DBI::dbConnect(duckdb()) on.exit(DBI::dbDisconnect(con, shutdown = TRUE)) @@ -24,6 +26,8 @@ test_that("Parquet files can be registered with dplyr::tbl()", { test_that("Object cache can be enabled for parquet files with dplyr::tbl()", { + skip_if_not_installed("dplyr") + con <- DBI::dbConnect(duckdb()) on.exit(DBI::dbDisconnect(con, shutdown = TRUE)) @@ -38,6 +42,8 @@ test_that("Object cache can be enabled for parquet files with dplyr::tbl()", { test_that("CSV files can be registered with dplyr::tbl()", { + skip_if_not_installed("dplyr") + path <- file.path(tempdir(), "duckdbtest.csv") write.csv(iris, file = path) on.exit(unlink(path)) @@ -55,6 +61,8 @@ test_that("CSV files can be registered with dplyr::tbl()", { }) test_that("Other replacement scans or functions can be registered with dplyr::tbl()", { + skip_if_not_installed("dplyr") + con <- DBI::dbConnect(duckdb()) on.exit(DBI::dbDisconnect(con, shutdown = TRUE)) @@ -64,9 +72,11 @@ test_that("Other replacement scans or functions can be registered with dplyr::tb }) test_that("Strings tagged as SQL will be handled correctly with dplyr::tbl()", { + skip_if_not_installed("dplyr") + con <- DBI::dbConnect(duckdb()) on.exit(DBI::dbDisconnect(con, shutdown = TRUE)) - + rs <- dplyr::tbl(con, dplyr::sql("SELECT 1")) expect_true(inherits(rs, "tbl_duckdb_connection")) expect_true(rs %>% dplyr::collect() == 1)