Repository navigation
Description
I have a sample package, https://github.com/dcaseykc/odbctest, that contains one function-- hello. hello's purpose is to open a database connection via odbc, close it, and then return 1.
When I test the package (e.g. testthat::test_file) with valid credentials in the main test file I get a semi-mysterious error:
In is.call(expr) && as.character(expr[[1]]) %in% c("<-", "=") :
'length(x) = 3 > 1' in coercion to 'logical(1)'
Based on my research, it seems like this error is the R interpreter (or similar) finding an if statement with a logical vector of length > 1
When I reran things with Sys.setenv('_R_CHECK_LENGTH_1_LOGIC2_'='verbose') I got the error trace I've posted below. I know the traceback mostly describes/refers to some code from the odbc package , but I've posted this issue here because the issue does not pop up when running the offending test code manually (e.g. outside the test_that block. That said, please tell me if I should migrate this report to the odbc maintainers.
Also, apologizes for not having things entirely self contained. Setting up a temp DB that works with odbc is a bit outside of my wheelhouse. I will investigate how to do that and update this issue I've I'm able to figure it out.
> testthat::test_file(path = './tests/testthat/test-hello.R')
══ Testing test-hello.R ═════════════════════════════════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] Done!
----------- FAILURE REPORT --------------
--- failure: length > 1 in coercion to logical ---
--- srcref ---
:
--- package (from environment) ---
odbc
--- call from context ---
doTryCatch(return(expr), name, parentenv, handler)
--- call from argument ---
is.call(expr) && as.character(expr[[1]]) %in% c("<-", "=")
--- R stacktrace ---
where 1: doTryCatch(return(expr), name, parentenv, handler)
where 2: tryCatchOne(expr, names, parentenv, handlers[[1L]])
where 3: tryCatchList(expr, classes, parentenv, handlers)
where 4: tryCatch({
if (is.call(expr) && as.character(expr[[1]]) %in% c("<-",
"=") && "dbConnect" %in% as.character(expr[[3]][[1]])) {
on_connection_opened(eval(expr[[2]]), paste(c("library(DBI)",
deparse(expr)), collapse = "\n"))
}
}, error = function(e) {
warning("Could not notify connection observer. ", e$message,
call. = FALSE)
})
where 5: cb(expr, value, succeeded, visible)
--- value of length: 3 type: logical ---
[1] FALSE FALSE FALSE
--- function from context ---
function (expr, name, parentenv, handler)
{
.Internal(.addCondHands(name, list(handler), parentenv, environment(),
FALSE))
expr
}
<bytecode: 0x000001ec170c09f0>
<environment: 0x000001ec2b9c1438>
--- function search by body ---
----------- END OF FAILURE REPORT --------------
warning messages from top-level task callback '1'
Warning message:
Could not notify connection observer. 'length(x) = 3 > 1' in coercion to 'logical(1)'
sessionInfo:
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] odbctest_0.1.0 testthat_3.1.4 keyring_1.3.0 DBI_1.1.2 odbc_1.3.3
loaded via a namespace (and not attached):
[1] xfun_0.30 remotes_2.4.2 purrr_0.3.4 rcmdcheck_1.4.0
[5] vctrs_0.4.1 usethis_2.1.5 utf8_1.2.2 blob_1.2.3
[9] rlang_1.0.2 pkgbuild_1.3.1 pillar_1.7.0 glue_1.6.2
[13] withr_2.5.0 waldo_0.4.0 xopen_1.0.0 bit64_4.0.5
[17] sessioninfo_1.2.2 lifecycle_1.0.1 stringr_1.4.0 devtools_2.4.3
[21] evaluate_0.15 memoise_2.0.1 knitr_1.39 callr_3.7.0
[25] fastmap_1.1.0 ps_1.7.0 curl_4.3.2 fansi_1.0.3
[29] highr_0.9 Rcpp_1.0.8.3 cachem_1.0.6 desc_1.4.1
[33] pkgload_1.2.4 fs_1.5.2 bit_4.0.4 brio_1.1.3
[37] hms_1.1.1 digest_0.6.29 stringi_1.7.6 processx_3.5.3
[41] rprojroot_2.0.3 cli_3.3.0 tools_4.2.0 magrittr_2.0.3
[45] tibble_3.1.6 crayon_1.5.1 whisker_0.4 pkgconfig_2.0.3
[49] ellipsis_0.3.2 data.table_1.14.2 xml2_1.3.3 prettyunits_1.1.1
[53] assertthat_0.2.1 roxygen2_7.1.2 rstudioapi_0.13 R6_2.5.1
[57] compiler_4.2.0
Activity
TBlackmore commentedon Jul 13, 2022
I've encountered the same issue. I'm trying to initialize a db connection using odbc driver in my helper.R.
I get the following error on executing devtools::load_all()
SessionInfo:
hadley commentedon Sep 19, 2022
I'm 90% certain this a odbc issue so can you please file it there?