Skip to content

DuckDB tables throw error when passed to create_agent() #635

@petrbouchal

Description

@petrbouchal

Prework

Description

DuckDB-backed tables cannot be passed to create_agent() - this emits an ! argument is of length zero error. This manifests on MacOS, Windows and Ubuntu. Bizarrely, it only happens when running code line by line. When executing a script, it does not happen.

The same issue does not manifest with SQLite. It does also show up when the DuckDB table is a view representing a registered Arrow dataset. It does not manifest when the tbl() call is put directly inside the create_informant() call (see reprex below).

The cause is in pointblank:::get_tbl_dbi_src_info() which does not capture the DB signature because it begins with newlines. It is not clear why in some situations (line by line execution) the newlines are there and not in others.

More broadly, could create_informant() rely on the class of the object to detect its type? e.g.

class(tbl_db)

> [1] "tbl_duckdb_connection" "tbl_dbi"               "tbl_sql"               "tbl_lazy"             
> [5] "tbl" 

Reproducible example

  • Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • Readable: format your code according to the tidyverse style guide.
library(pointblank)
library(duckdb)
library(dplyr)

con <- dbConnect(duckdb::duckdb(), "test.duckdb")
tbl_db <- copy_to(con, airquality, 
  "airquality_cp", temporary = TRUE, overwrite = TRUE)
tbl_db2 <- tbl(con, "airquality_cp")

create_agent(tbl(con, "airquality_cp")) # runs in any case
create_agent(tbl_db) # error if run line by line
create_agent(tbl_db2) # error if run line by line

tbl_db$src$con
pointblank:::get_tbl_dbi_src_details(tbl_db) # returns empty string "" if run line by line

dbDisconnect(con)

Expected result

I would expect this to work no matter the mode of execution.

Session info

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Prague
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.1.4            duckdb_1.3.0           DBI_1.2.3              pointblank_0.12.2.9000 reprex_2.1.1          
[6] devtools_2.4.5         usethis_3.1.0         

loaded via a namespace (and not attached):
 [1] gt_1.0.0            sass_0.4.10         rappdirs_0.3.3      generics_0.1.4      xml2_1.3.8         
 [6] stringi_1.8.7       digest_0.6.37       magrittr_2.0.3      pkgload_1.4.0.9000  fastmap_1.2.0      
[11] pkgbuild_1.4.8      sessioninfo_1.2.2   urlchecker_1.0.1    promises_1.3.2      purrr_1.1.0        
[16] coro_1.1.0          httr2_1.1.2         cli_3.6.5.9000      shiny_1.10.0        rlang_1.1.6        
[21] dbplyr_2.5.0        litedown_0.7        commonmark_2.0.0    ellipsis_0.3.2      remotes_2.5.0      
[26] withr_3.0.2         cachem_1.1.0        tools_4.4.1         memoise_2.0.1       nanonext_1.6.0     
[31] httpuv_1.6.15       vctrs_0.6.5         R6_2.6.1            mime_0.13           lifecycle_1.0.4    
[36] stringr_1.5.1       mcptools_0.0.0.9000 fs_1.6.6            htmlwidgets_1.6.4   miniUI_0.1.1.1     
[41] pkgconfig_2.0.3     pillar_1.11.0       later_1.4.1         glue_1.8.0          profvis_0.3.8      
[46] Rcpp_1.1.0          xfun_0.52           tibble_3.3.0        tidyselect_1.2.1    xtable_1.8-4       
[51] htmltools_0.5.8.1   ellmer_0.2.1        compiler_4.4.1      blastula_0.3.6      S7_0.2.0           
[56] markdown_2.0 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions