Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when supplying table_names in dm_from_con() #1936

Open
jesse-smith opened this issue Aug 2, 2023 · 1 comment
Open

Error when supplying table_names in dm_from_con() #1936

jesse-smith opened this issue Aug 2, 2023 · 1 comment
Milestone

Comments

@jesse-smith
Copy link

When table_names is supplied to dm_from_con(), an error is thrown due to attempting to use the @ operator on a character vector. I think this changed to accomodate the new .names argument (#1790). It seems as though @owenjonesuob has already submitted a PR (#1934) to fix a different issue resulting from this; I think this should also fix the issue I'm documenting. Reprex for issue is below.

library(dm)
#> Warning: package 'dm' was built under R version 4.3.1
#> 
#> Attaching package: 'dm'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(nycflights13)
#> Warning: package 'nycflights13' was built under R version 4.3.1

# Create in-memory SQLite database
dm <- dm_nycflights13()
con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
copy_dm_to(con_sqlite, dm)

# Run `dm_from_con()` w/o `table_names` (set `learn_keys = FALSE` to avoid warnings)
dm_from_con(con_sqlite, learn_keys = FALSE)
#> ── Table source ────────────────────────────────────────────────────────────────
#> src:  sqlite 3.41.2 [:memory:]
#> ── Metadata ────────────────────────────────────────────────────────────────────
#> Tables: `airlines_1_2023_08_02_11_10_57_425818_20696`, `airports_1_2023_08_02_11_10_57_425818_20696`, `flights_1_2023_08_02_11_10_57_425818_20696`, `planes_1_2023_08_02_11_10_57_425818_20696`, `weather_1_2023_08_02_11_10_57_425818_20696`
#> Columns: 53
#> Primary keys: 0
#> Foreign keys: 0

# Run `dm_from_con()` w/ `table_nms` - throws error
tbl_nms <- DBI::dbListTables(con_sqlite)
dm_from_con(con_sqlite, learn_keys = FALSE, table_names = tbl_nms)
#> Error in `purrr::map_chr()`:
#> ℹ In index: 1.
#> Caused by error in `.x@name`:
#> ! no applicable method for `@` applied to an object of class "character"
#> Backtrace:
#>      ▆
#>   1. ├─dm::dm_from_con(con_sqlite, learn_keys = FALSE, table_names = tbl_nms)
#>   2. │ └─purrr::map_chr(src_tbl_names, ~.x@name[["table"]])
#>   3. │   └─purrr:::map_("character", .x, .f, ..., .progress = .progress)
#>   4. │     ├─purrr:::with_indexed_errors(...)
#>   5. │     │ └─base::withCallingHandlers(...)
#>   6. │     ├─purrr:::call_with_cleanup(...)
#>   7. │     └─dm (local) .f(.x[[i]], ...)
#>   8. └─base::.handleSimpleError(...)
#>   9.   └─purrr (local) h(simpleError(msg, call))
#>  10.     └─cli::cli_abort(...)
#>  11.       └─rlang::abort(...)

# Cleanup
DBI::dbDisconnect(con_sqlite)
rm(con_sqlite, dm, tbl_nms)
gc()
#>           used (Mb) gc trigger  (Mb) max used  (Mb)
#> Ncells 1286024 68.7    2531651 135.3  2531651 135.3
#> Vcells 2324009 17.8    8388608  64.0  2981620  22.8

Created on 2023-08-02 with reprex v2.0.2

@krlmlr krlmlr added this to the learn milestone Aug 20, 2023
@owenjonesuob
Copy link
Contributor

Possibly fixed by #2148 - I've just tried the reprex with v1.0.10 (from CRAN) and all seemed to work well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants