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

docs: Add stability to README output #65

Merged
merged 8 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ knitr::opts_chunk$set(
pkgload::load_all()

set.seed(20230702)

clean_output <- function(x, options) {
x <- gsub("0x[0-9a-f]+", "0xdeadbeef", x)
x <- gsub("dataframe_[0-9]*_[0-9]*", " dataframe_42_42 ", x)
x <- gsub("[0-9]*\\.___row_number ASC", " 42.___row_number ASC ", x)
x
}

local({
hook_source <- knitr::knit_hooks$get('document')
knitr::knit_hooks$set(document = clean_output)
})

Sys.setenv(DUCKPLYR_OUTPUT_ORDER = TRUE)
```

# duckplyr
Expand Down
59 changes: 38 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,26 @@ duckdb is responsible for eventually carrying out the operations. Despite the la
<span><span class='nv'>out</span> <span class='o'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%&gt;%</a></span></span>
<span> <span class='nf'><a href='https://dplyr.tidyverse.org/reference/explain.html'>explain</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span><span class='c'>#&gt; ┌───────────────────────────┐</span></span>
<span><span class='c'>#&gt; │ HASH_GROUP_BY │</span></span>
<span><span class='c'>#&gt; │ ORDER_BY │</span></span>
<span><span class='c'>#&gt; │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │</span></span>
<span><span class='c'>#&gt; │ #0 │</span></span>
<span><span class='c'>#&gt; │ #1 │</span></span>
<span><span class='c'>#&gt; │ mean(#2) │</span></span>
<span><span class='c'>#&gt; │ ORDERS: │</span></span>
<span><span class='c'>#&gt; │ dataframe_42_42 │</span></span>
<span><span class='c'>#&gt; │ 42.___row_number ASC │</span></span>
<span><span class='c'>#&gt; └─────────────┬─────────────┘ </span></span>
<span><span class='c'>#&gt; ┌─────────────┴─────────────┐</span></span>
<span><span class='c'>#&gt; │ PROJECTION │</span></span>
<span><span class='c'>#&gt; │ HASH_GROUP_BY │</span></span>
<span><span class='c'>#&gt; │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │</span></span>
<span><span class='c'>#&gt; │ species │</span></span>
<span><span class='c'>#&gt; │ sex │</span></span>
<span><span class='c'>#&gt; │ bill_area │</span></span>
<span><span class='c'>#&gt; │ #0 │</span></span>
<span><span class='c'>#&gt; │ #1 │</span></span>
<span><span class='c'>#&gt; │ min(#2) │</span></span>
<span><span class='c'>#&gt; │ mean(#3) │</span></span>
<span><span class='c'>#&gt; └─────────────┬─────────────┘ </span></span>
<span><span class='c'>#&gt; ┌─────────────┴─────────────┐</span></span>
<span><span class='c'>#&gt; │ PROJECTION │</span></span>
<span><span class='c'>#&gt; │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │</span></span>
<span><span class='c'>#&gt; │ species │</span></span>
<span><span class='c'>#&gt; │ sex │</span></span>
<span><span class='c'>#&gt; │ ___row_number │</span></span>
<span><span class='c'>#&gt; │ bill_area │</span></span>
<span><span class='c'>#&gt; └─────────────┬─────────────┘ </span></span>
<span><span class='c'>#&gt; ┌─────────────┴─────────────┐</span></span>
Expand All @@ -104,6 +106,18 @@ duckdb is responsible for eventually carrying out the operations. Despite the la
<span><span class='c'>#&gt; │ EC: 344 │</span></span>
<span><span class='c'>#&gt; └─────────────┬─────────────┘ </span></span>
<span><span class='c'>#&gt; ┌─────────────┴─────────────┐</span></span>
<span><span class='c'>#&gt; │ STREAMING_WINDOW │</span></span>
<span><span class='c'>#&gt; │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │</span></span>
<span><span class='c'>#&gt; │ ROW_NUMBER() OVER () │</span></span>
<span><span class='c'>#&gt; └─────────────┬─────────────┘ </span></span>
<span><span class='c'>#&gt; ┌─────────────┴─────────────┐</span></span>
<span><span class='c'>#&gt; │ PROJECTION │</span></span>
<span><span class='c'>#&gt; │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │</span></span>
<span><span class='c'>#&gt; │ species │</span></span>
<span><span class='c'>#&gt; │ sex │</span></span>
<span><span class='c'>#&gt; │ bill_area │</span></span>
<span><span class='c'>#&gt; └─────────────┬─────────────┘ </span></span>
<span><span class='c'>#&gt; ┌─────────────┴─────────────┐</span></span>
<span><span class='c'>#&gt; │ R_DATAFRAME_SCAN │</span></span>
<span><span class='c'>#&gt; │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │</span></span>
<span><span class='c'>#&gt; │ data.frame │</span></span>
Expand All @@ -125,9 +139,12 @@ All data frame operations are supported. Computation happens upon the first requ
<span><span class='c'>#&gt; --- Relation Tree ---</span></span>
<span><span class='c'>#&gt; ---------------------</span></span>
<span><span class='c'>#&gt; Filter [!=(species, 'Gentoo')]</span></span>
<span><span class='c'>#&gt; Aggregate [species, sex, mean(bill_area)]</span></span>
<span><span class='c'>#&gt; Projection [species as species, island as island, bill_length_mm as bill_length_mm, bill_depth_mm as bill_depth_mm, flipper_length_mm as flipper_length_mm, body_mass_g as body_mass_g, sex as sex, "year" as year, *(bill_length_mm, bill_depth_mm) as bill_area]</span></span>
<span><span class='c'>#&gt; r_dataframe_scan(0x10c4c7628)</span></span>
<span><span class='c'>#&gt; Projection [species as species, sex as sex, mean_bill_area as mean_bill_area]</span></span>
<span><span class='c'>#&gt; Order [___row_number ASC]</span></span>
<span><span class='c'>#&gt; Aggregate [species, sex, min(___row_number), mean(bill_area)]</span></span>
<span><span class='c'>#&gt; Projection [species as species, island as island, bill_length_mm as bill_length_mm, bill_depth_mm as bill_depth_mm, flipper_length_mm as flipper_length_mm, body_mass_g as body_mass_g, sex as sex, "year" as year, bill_area as bill_area, row_number() OVER () as ___row_number]</span></span>
<span><span class='c'>#&gt; Projection [species as species, island as island, bill_length_mm as bill_length_mm, bill_depth_mm as bill_depth_mm, flipper_length_mm as flipper_length_mm, body_mass_g as body_mass_g, sex as sex, "year" as year, *(bill_length_mm, bill_depth_mm) as bill_area]</span></span>
<span><span class='c'>#&gt; r_dataframe_scan(0xdeadbeef)</span></span>
<span><span class='c'>#&gt; </span></span>
<span><span class='c'>#&gt; ---------------------</span></span>
<span><span class='c'>#&gt; -- Result Columns --</span></span>
Expand All @@ -136,7 +153,7 @@ All data frame operations are supported. Computation happens upon the first requ
<span><span class='c'>#&gt; - sex (VARCHAR)</span></span>
<span><span class='c'>#&gt; - mean_bill_area (DOUBLE)</span></span>
<span><span class='c'>#&gt; </span></span>
<span><span class='c'>#&gt; [1] 770.2627 656.8523 819.7503 694.9360 984.2279</span></span></pre>
<span><span class='c'>#&gt; [1] 770.2627 656.8523 694.9360 819.7503 984.2279</span></span></pre>

After the computation has been carried out, the results are available immediately:

Expand All @@ -147,8 +164,8 @@ After the computation has been carried out, the results are available immediatel
<span><span class='c'>#&gt; <span style='color: #555555; font-style: italic;'>&lt;chr&gt;</span> <span style='color: #555555; font-style: italic;'>&lt;chr&gt;</span> <span style='color: #555555; font-style: italic;'>&lt;dbl&gt;</span></span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>1</span> Adelie male 770.</span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>2</span> Adelie female 657.</span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>3</span> Chinstrap female 820.</span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>4</span> Adelie <span style='color: #BB0000;'>NA</span> 695.</span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>3</span> Adelie <span style='color: #BB0000;'>NA</span> 695.</span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>4</span> Chinstrap female 820.</span></span>
<span><span class='c'>#&gt; <span style='color: #555555;'>5</span> Chinstrap male 984.</span></span></pre>

### Session-wide usage
Expand All @@ -169,10 +186,7 @@ This is the same query as above, without [`as_duckplyr_df()`](https://duckdblabs
<span> <span class='nf'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span><span class='o'>(</span><span class='nf'><a href='https://dplyr.tidyverse.org/reference/across.html'>across</a></span><span class='o'>(</span><span class='nf'>where</span><span class='o'>(</span><span class='nv'>is.factor</span><span class='o'>)</span>, <span class='nv'>as.character</span><span class='o'>)</span><span class='o'>)</span> <span class='o'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%&gt;%</a></span></span>
<span> <span class='nf'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span><span class='o'>(</span>bill_area <span class='o'>=</span> <span class='nv'>bill_length_mm</span> <span class='o'>*</span> <span class='nv'>bill_depth_mm</span><span class='o'>)</span> <span class='o'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%&gt;%</a></span></span>
<span> <span class='nf'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarize</a></span><span class='o'>(</span>.by <span class='o'>=</span> <span class='nf'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='o'>(</span><span class='nv'>species</span>, <span class='nv'>sex</span><span class='o'>)</span>, mean_bill_area <span class='o'>=</span> <span class='nf'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span><span class='o'>(</span><span class='nv'>bill_area</span><span class='o'>)</span><span class='o'>)</span> <span class='o'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%&gt;%</a></span></span>
<span> <span class='nf'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span><span class='o'>(</span><span class='nv'>species</span> <span class='o'>!=</span> <span class='s'>"Gentoo"</span><span class='o'>)</span></span>
<span><span class='c'>#&gt; Error processing with relational.</span></span>
<span><span class='c'>#&gt; <span style='font-weight: bold;'>Caused by error in `duckdb_rel_from_df()`:</span></span></span>
<span><span class='c'>#&gt; <span style='color: #BBBB00;'>!</span> Can't convert factor columns to relational. Affected column: `species`.</span></span></pre>
<span> <span class='nf'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span><span class='o'>(</span><span class='nv'>species</span> <span class='o'>!=</span> <span class='s'>"Gentoo"</span><span class='o'>)</span></span></pre>

The result is a plain tibble now:

Expand All @@ -189,9 +203,12 @@ Querying the number of rows also starts the computation:
<span><span class='c'>#&gt; --- Relation Tree ---</span></span>
<span><span class='c'>#&gt; ---------------------</span></span>
<span><span class='c'>#&gt; Filter [!=(species, 'Gentoo')]</span></span>
<span><span class='c'>#&gt; Aggregate [species, sex, mean(bill_area)]</span></span>
<span><span class='c'>#&gt; Projection [species as species, island as island, bill_length_mm as bill_length_mm, bill_depth_mm as bill_depth_mm, flipper_length_mm as flipper_length_mm, body_mass_g as body_mass_g, sex as sex, "year" as year, *(bill_length_mm, bill_depth_mm) as bill_area]</span></span>
<span><span class='c'>#&gt; r_dataframe_scan(0x10a81d568)</span></span>
<span><span class='c'>#&gt; Projection [species as species, sex as sex, mean_bill_area as mean_bill_area]</span></span>
<span><span class='c'>#&gt; Order [___row_number ASC]</span></span>
<span><span class='c'>#&gt; Aggregate [species, sex, min(___row_number), mean(bill_area)]</span></span>
<span><span class='c'>#&gt; Projection [species as species, island as island, bill_length_mm as bill_length_mm, bill_depth_mm as bill_depth_mm, flipper_length_mm as flipper_length_mm, body_mass_g as body_mass_g, sex as sex, "year" as year, bill_area as bill_area, row_number() OVER () as ___row_number]</span></span>
<span><span class='c'>#&gt; Projection [species as species, island as island, bill_length_mm as bill_length_mm, bill_depth_mm as bill_depth_mm, flipper_length_mm as flipper_length_mm, body_mass_g as body_mass_g, sex as sex, "year" as year, *(bill_length_mm, bill_depth_mm) as bill_area]</span></span>
<span><span class='c'>#&gt; r_dataframe_scan(0xdeadbeef)</span></span>
<span><span class='c'>#&gt; </span></span>
<span><span class='c'>#&gt; ---------------------</span></span>
<span><span class='c'>#&gt; -- Result Columns --</span></span>
Expand Down
Loading