
Show the polars code equivalent to the tidypolars pipeline
Source:R/show_query.R
show_query.polars_data_frame.Rdshow_query() prints the pure polars code that tidypolars runs in the
background. This code can be copy-pasted and run with polars only (the
input data must be assigned to the name displayed in the first line of the
query).
Recording the query is disabled by default, meaning that show_query() will
error with an informative message. It can be enabled with
options(tidypolars_record_query = TRUE) (see tidypolars_options).
To keep the output readable and close to hand-written polars code, R
operators are used instead of their method equivalent (e.g. a$add(b) is
shown as a + b), and user-defined functions are displayed as a call
rather than expanded into the operations they perform internally.
Long values coming from the calling environment are referred to by the name
of the object they come from, so that the printed code stays copy-pasteable.
Values that are too long to display and are not bound to a name, such as a
long inline vector, are shown as a placeholder like
`<numeric of length 200>`.
Usage
# S3 method for class 'polars_data_frame'
show_query(x, ...)
# S3 method for class 'polars_lazy_frame'
show_query(x, ...)Value
The input, invisibly. This function is called for its side effect of printing the polars query.
Examples
withr::with_options(
list(tidypolars_record_query = TRUE),
mtcars |>
as_polars_lf() |>
filter(cyl == 4) |>
mutate(
mpg2 = mpg * 2,
mpg2_max = max(mpg2),
.by = am
) |>
show_query()
)
#> as_polars_lf(mtcars)$
#> filter(pl$col("cyl") == pl$lit(4))$
#> with_columns(mpg2 = (pl$col("mpg") * pl$lit(2))$over("am"))$
#> with_columns(
#> mpg2_max = pl$when(pl$col("mpg2")$has_nulls())$
#> then(NA)$
#> otherwise(pl$col("mpg2")$max())$
#> over("am")
#> )