Allowing dbplyr lazy table as input data for PivotTable #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #67 dbplyr processing library
Description
dbplyr uses dplyr syntax, so I don't think we need an additional processing library. By expanding the allowable class for the input data to include dbplyr lazy data that represent database table/query and adding the instruction to download the database calculation to R, pivottabler does work with table on databases.
The following code shows how a table in a database (SQLite) can be used to calculate a pivottable. I have also run a similar code using table in my organisation database (in Snowflake)
`library(dplyr)
library(dbplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:")
DBI::dbWriteTable(con, "CO2", as.data.frame(CO2))
co2_db <- tbl(con, "CO2")
pt <- PivotTable$new()
pt$addData(co2_db)
pt$addRowDataGroups("Plant")
pt$addColumnDataGroups("Type")
pt$addColumnDataGroups("Treatment")
pt$defineCalculation(calculationName="TotalUptake", summariseExpression="sum(uptake)")
pt$renderPivot()`
Changes made
Checklist
Output of devtools::test()
ℹ Testing pivottabler
✔ | F W S OK | Context
✔ | 8 | BASIC TESTS [1.4s]
✔ | 5 | SMOKE TESTS [1.5s]
✔ | 8 | ILLEGAL NAME TESTS [2.4s]
✔ | 4 | QUICK-PIVOT TESTS [1.8s]
✔ | 24 | BASIC LAYOUT TESTS [2.1s]
✔ | 10 | DATA GROUP TESTS [3.8s]
✔ | 2 8 | CALCULATION TESTS [4.2s]
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Warning (test-A-07-calculationTests.R:80): calculation tests: calculate dply summarise: batch dplyr
package 'dplyr' was built under R version 4.2.3
Backtrace:
at test-A-07-calculationTests.R:80:6
Warning (test-A-07-calculationTests.R:81): calculation tests: calculate dply summarise: batch dplyr
package 'lubridate' was built under R version 4.2.3
Backtrace:
at test-A-07-calculationTests.R:81:6
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔ | 2 | VISUAL TOTALS TESTS [0.5s]
✔ | 9 | THEMING TESTS [0.7s]
✔ | 2 | EMPTY GROUP TESTS [0.1s]
✔ | 1 6 | EXPORT TESTS [2.1s]
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Warning (test-B-12-exportTests.R:284): export tests: as basictable: batch dplyr
package 'basictabler' was built under R version 4.2.3
Backtrace:
at test-B-12-exportTests.R:284:6
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔ | 6 | LATEX TESTS [1.3s]
✔ | 6 | EXPORT OPTIONS TESTS [1.1s]
✔ | 6 | FIND GROUP TESTS [1.0s]
✔ | 4 | GET CELLS TESTS [2.5s]
✔ | 15 | FIND CELLS TESTS [2.1s]
✔ | 4 | IRREGULAR LAYOUT TESTS [0.5s]
✔ | 4 | CALCULATION CUSTOM FORMATTING TESTS [0.4s]
✔ | 4 | DATA GROUP CUSTOM FORMATTING TESTS [0.8s]
✔ | 3 | ALTERNATIVE LAYOUT TESTS [2.1s]
✔ | 2 | ROW GROUP HEADER BASIC LAYOUT TESTS [0.2s]
✔ | 4 | OUTLINE LAYOUT TESTS [1.8s]
✔ | 26 | PIVOT ROW/COLUMN TESTS [1.6s]
✔ | 9 | MAP STYLING TESTS [1.3s]
✔ | 12 | INTERSECTION TESTS
✔ | 12 | UNION TESTS
✔ | 8 | UNLIST TESTS
══ Results ═══════════════════════════════════════════════════════════════════════════════════════════════════
Duration: 41.0 s
[ FAIL 0 | WARN 3 | SKIP 0 | PASS 211 ]