From b2d4b6b02843aa802c3a55b49ed3700903e2dde9 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 26 Sep 2023 07:45:53 -0500 Subject: [PATCH] Prepare for upcoming R-devel change (#1369) Where `is.atomic(NULL)` will return `FALSE` --- R/sql-expr.R | 4 +++- R/translate-sql-window.R | 2 +- tests/testthat/test-sql-expr.R | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/R/sql-expr.R b/R/sql-expr.R index ea935367d..45501e6ff 100644 --- a/R/sql-expr.R +++ b/R/sql-expr.R @@ -47,7 +47,9 @@ sql_call2 <- function(.fn, ..., con = sql_current_con()) { replace_expr <- function(x, con) { - if (is.atomic(x) || blob::is_blob(x)) { + if (is.null(x)) { + "NULL" + } else if (is.atomic(x) || blob::is_blob(x)) { as.character(escape(unname(x), con = con)) } else if (is.name(x)) { as.character(x) diff --git a/R/translate-sql-window.R b/R/translate-sql-window.R index 8cf9dc40c..aa01d6b70 100644 --- a/R/translate-sql-window.R +++ b/R/translate-sql-window.R @@ -454,7 +454,7 @@ translate_window_where_all <- function(x, window_funs = common_window_funs()) { } window_where <- function(expr, comp) { - stopifnot(is.call(expr) || is.name(expr) || is.atomic(expr)) + stopifnot(is.call(expr) || is.name(expr) || is.atomic(expr) || is.null(expr)) check_list(comp) list( diff --git a/tests/testthat/test-sql-expr.R b/tests/testthat/test-sql-expr.R index a51657934..88e26a252 100644 --- a/tests/testthat/test-sql-expr.R +++ b/tests/testthat/test-sql-expr.R @@ -1,3 +1,8 @@ +test_that("NULL becomes SQL NULL", { + con <- simulate_dbi() + expect_equal(sql_expr(NULL), sql("NULL")) +}) + test_that("atomic vectors are escaped", { con <- simulate_dbi()