Title: | A 'DuckDB'-Backed Version of 'dplyr' |
---|---|
Description: | A drop-in replacement for 'dplyr', powered by 'DuckDB' for performance. Offers convenient utilities for working with in-memory and larger-than-memory data while retaining full 'dplyr' compatibility. |
Authors: | Hannes Mühleisen [aut] , Kirill Müller [aut, cre] , Posit Software, PBC [cph, fnd] |
Maintainer: | Kirill Müller <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.99.99.9905 |
Built: | 2024-12-21 02:48:47 UTC |
Source: | https://github.com/tidyverse/duckplyr |
This is a method for the dplyr::anti_join()
generic.
anti_join()
returns all rows from x
without a match in y
.
## S3 method for class 'duckplyr_df' anti_join(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never"))
## S3 method for class 'duckplyr_df' anti_join(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never"))
x , y
|
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
... |
Other parameters passed onto methods. |
na_matches |
Should two |
library("dplyr") # for the data library("duckplyr") band_members %>% anti_join(band_instruments)
library("dplyr") # for the data library("duckplyr") band_members %>% anti_join(band_instruments)
This is a method for the dplyr::arrange()
generic.
See "Fallbacks" section for differences in implementation.
arrange()
orders the rows of a data frame by the values of selected
columns.
Unlike other dplyr verbs, arrange()
largely ignores grouping; you
need to explicitly mention grouping variables (or use .by_group = TRUE
)
in order to group by them, and functions of variables are evaluated
once per data frame, not once per group.
## S3 method for class 'duckplyr_df' arrange(.data, ..., .by_group = FALSE, .locale = NULL)
## S3 method for class 'duckplyr_df' arrange(.data, ..., .by_group = FALSE, .locale = NULL)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< |
.by_group |
If |
.locale |
The locale to sort character vectors in.
The C locale is not the same as English locales, such as |
You cannot use arrange.duckplyr_df
when:
.by_group = TRUE
,
providing a value for the .locale
argument,
providing a value for the dplyr.legacy_locale
option.
If you do the code will fall back to dplyr::arrange()
without any error.
library("duckplyr") arrange(mtcars, cyl, disp) arrange(mtcars, desc(disp))
library("duckplyr") arrange(mtcars, cyl, disp) arrange(mtcars, desc(disp))
The behavior of duckplyr can be fine-tuned with several environment variables, and one option.
DUCKPLYR_OUTPUT_ORDER
: If TRUE
, row output order is preserved.
The default may change the row order where dplyr would keep it stable.
Preserving the order leads to more complicated execution plans
with less potential for optimization, and thus may be slower.
DUCKPLYR_FORCE
: If TRUE
, fail if duckdb cannot handle a request.
DUCKPLYR_FALLBACK_INFO
: If TRUE
, print a message when a fallback to dplyr occurs
because duckdb cannot handle a request.
DUCKPLYR_CHECK_ROUNDTRIP
: If TRUE
, check if all columns are roundtripped perfectly
when creating a relational object from a data frame,
This is slow, and mostly useful for debugging.
The default is to check roundtrip of attributes.
DUCKPLYR_EXPERIMENTAL
: If TRUE
, pass experimental = TRUE
to certain duckdb functions.
Currently unused.
DUCKPLYR_METHODS_OVERWRITE
: If TRUE
, call methods_overwrite()
when the package is loaded.
See fallback for more options related to logging and uploading of fallback events.
# Sys.setenv(DUCKPLYR_OUTPUT_ORDER = TRUE) data.frame(a = 3:1) %>% as_duckplyr_df() %>% inner_join(data.frame(a = 1:4), by = "a") withr::with_envvar(c(DUCKPLYR_OUTPUT_ORDER = "TRUE"), { data.frame(a = 3:1) %>% as_duckplyr_df() %>% inner_join(data.frame(a = 1:4), by = "a") }) # Sys.setenv(DUCKPLYR_FORCE = TRUE) add_one <- function(x) { x + 1 } data.frame(a = 3:1) %>% as_duckplyr_df() %>% mutate(b = add_one(a)) try(withr::with_envvar(c(DUCKPLYR_FORCE = "TRUE"), { data.frame(a = 3:1) %>% as_duckplyr_df() %>% mutate(b = add_one(a)) })) # Sys.setenv(DUCKPLYR_FALLBACK_INFO = TRUE) withr::with_envvar(c(DUCKPLYR_FALLBACK_INFO = "TRUE"), { data.frame(a = 3:1) %>% as_duckplyr_df() %>% mutate(b = add_one(a)) })
# Sys.setenv(DUCKPLYR_OUTPUT_ORDER = TRUE) data.frame(a = 3:1) %>% as_duckplyr_df() %>% inner_join(data.frame(a = 1:4), by = "a") withr::with_envvar(c(DUCKPLYR_OUTPUT_ORDER = "TRUE"), { data.frame(a = 3:1) %>% as_duckplyr_df() %>% inner_join(data.frame(a = 1:4), by = "a") }) # Sys.setenv(DUCKPLYR_FORCE = TRUE) add_one <- function(x) { x + 1 } data.frame(a = 3:1) %>% as_duckplyr_df() %>% mutate(b = add_one(a)) try(withr::with_envvar(c(DUCKPLYR_FORCE = "TRUE"), { data.frame(a = 3:1) %>% as_duckplyr_df() %>% mutate(b = add_one(a)) })) # Sys.setenv(DUCKPLYR_FALLBACK_INFO = TRUE) withr::with_envvar(c(DUCKPLYR_FALLBACK_INFO = "TRUE"), { data.frame(a = 3:1) %>% as_duckplyr_df() %>% mutate(b = add_one(a)) })
This is a method for the dplyr::count()
generic.
See "Fallbacks" section for differences in implementation.
count()
lets you quickly count the unique values of one or more variables:
df %>% count(a, b)
is roughly equivalent to
df %>% group_by(a, b) %>% summarise(n = n())
.
count()
is paired with tally()
, a lower-level helper that is equivalent
to df %>% summarise(n = n())
. Supply wt
to perform weighted counts,
switching the summary from n = n()
to n = sum(wt)
.
## S3 method for class 'duckplyr_df' count( x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x) )
## S3 method for class 'duckplyr_df' count( x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x) )
x |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). |
... |
< |
wt |
<
|
sort |
If |
name |
The name of the new column in the output. If omitted, it will default to |
.drop |
Handling of factor levels that don't appear in the data, passed
on to For For |
You cannot use count.duckplyr_df
with complex expressions in ...
,
with .drop = FALSE
,
with sort = TRUE
.
If you do the code will fall back to dplyr::count()
without any error.
library("duckplyr") count(mtcars, am)
library("duckplyr") count(mtcars, am)
This is a method for the dplyr::distinct()
generic.
Keep only unique/distinct rows from a data frame.
This is similar to unique.data.frame()
but considerably faster.
## S3 method for class 'duckplyr_df' distinct(.data, ..., .keep_all = FALSE)
## S3 method for class 'duckplyr_df' distinct(.data, ..., .keep_all = FALSE)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< |
.keep_all |
If |
df <- tibble( x = sample(10, 100, rep = TRUE), y = sample(10, 100, rep = TRUE) ) nrow(df) nrow(distinct(df))
df <- tibble( x = sample(10, 100, rep = TRUE), y = sample(10, 100, rep = TRUE) ) nrow(df) nrow(distinct(df))
The duckplyr package relies on a DBI connection
to an in-memory database.
The duck_exec()
function allows running SQL statements
with this connection to, e.g., set up credentials
or attach other databases.
See https://duckdb.org/docs/configuration/overview.html
for more information on the configuration options.
duck_exec(sql, ..., con = NULL)
duck_exec(sql, ..., con = NULL)
sql |
The statement to run. |
... |
These dots are for future extensions and must be empty. |
con |
The connection, defaults to the default connection. |
The return value of the DBI::dbExecute()
call, invisibly.
duck_exec("SET threads TO 2")
duck_exec("SET threads TO 2")
These functions ingest data from a file. In many cases, these functions return immediately because they only read the metadata. The actual data is only read when it is actually processed.
duck_parquet()
reads a CSV file using DuckDB's read_parquet()
table function.
duck_csv()
reads a CSV file using DuckDB's read_csv_auto()
table function.
duck_json()
reads a JSON file using DuckDB's read_json()
table function.
duck_file()
uses arbitrary readers to read data.
See https://duckdb.org/docs/data/overview for a documentation
of the available functions and their options.
To read multiple files with the same schema,
pass a wildcard or a character vector to the path
argument,
duck_parquet(path, ..., lazy = TRUE, options = list()) duck_csv(path, ..., lazy = TRUE, options = list()) duck_json(path, ..., lazy = TRUE, options = list()) duck_file(path, table_function, ..., lazy = TRUE, options = list())
duck_parquet(path, ..., lazy = TRUE, options = list()) duck_csv(path, ..., lazy = TRUE, options = list()) duck_json(path, ..., lazy = TRUE, options = list()) duck_file(path, table_function, ..., lazy = TRUE, options = list())
path |
Path to files, glob patterns |
... |
These dots are for future extensions and must be empty. |
lazy |
Logical, whether to create a lazy duckplyr frame.
If |
options |
Arguments to the DuckDB function
indicated by |
table_function |
The name of a table-valued
DuckDB function such as |
By default, a lazy duckplyr frame is created.
This means that all the data can be shown and all dplyr verbs can be used,
but attempting to access the columns of the data frame or using an unsupported verb,
data type, or function will result in an error.
Pass lazy = FALSE
to transparently switch to local processing as needed,
or use dplyr::collect()
to explicitly materialize and continue local processing.
A duckplyr frame, see as_duck_tbl()
for details.
# Create simple CSV file path <- tempfile("duckplyr_test_", fileext = ".csv") write.csv(data.frame(a = 1:3, b = letters[4:6]), path, row.names = FALSE) # Reading is immediate df <- duck_csv(path) # Names are always available names(df) # Materialization upon access is turned off by default try(print(df$a)) # Materialize explicitly collect(df)$a # Automatic materialization with lazy = FALSE df <- duck_csv(path, lazy = FALSE) df$a # Specify column types duck_csv( path, options = list(delim = ",", types = list(c("DOUBLE", "VARCHAR"))) ) # Create and read a simple JSON file path <- tempfile("duckplyr_test_", fileext = ".json") writeLines('[{"a": 1, "b": "x"}, {"a": 2, "b": "y"}]', path) # Reading needs the json extension duck_exec("INSTALL json") duck_exec("LOAD json") duck_json(path)
# Create simple CSV file path <- tempfile("duckplyr_test_", fileext = ".csv") write.csv(data.frame(a = 1:3, b = letters[4:6]), path, row.names = FALSE) # Reading is immediate df <- duck_csv(path) # Names are always available names(df) # Materialization upon access is turned off by default try(print(df$a)) # Materialize explicitly collect(df)$a # Automatic materialization with lazy = FALSE df <- duck_csv(path, lazy = FALSE) df$a # Specify column types duck_csv( path, options = list(delim = ",", types = list(c("DOUBLE", "VARCHAR"))) ) # Create and read a simple JSON file path <- tempfile("duckplyr_test_", fileext = ".json") writeLines('[{"a": 1, "b": "x"}, {"a": 2, "b": "y"}]', path) # Reading needs the json extension duck_exec("INSTALL json") duck_exec("LOAD json") duck_json(path)
Runs a query and returns it as a duckplyr frame.
duck_sql(sql, ..., lazy = TRUE, con = NULL)
duck_sql(sql, ..., lazy = TRUE, con = NULL)
sql |
The SQL to run. |
... |
These dots are for future extensions and must be empty. |
lazy |
Logical, whether to create a lazy duckplyr frame.
If |
con |
The connection, defaults to the default connection. |
Using data frames from the calling environment is not supported yet, see https://github.com/duckdb/duckdb-r/issues/645 for details.
duck_sql("FROM duckdb_settings()")
duck_sql("FROM duckdb_settings()")
Data frames backed by duckplyr have a special class, "duckplyr_df"
,
in addition to the default classes.
This ensures that dplyr methods are dispatched correctly.
For such objects,
dplyr verbs such as dplyr::mutate()
, dplyr::select()
or dplyr::filter()
will attempt to use DuckDB.
If this is not possible, the original dplyr implementation is used.
duck_tbl()
works like tibble::tibble()
.
In contrast to dbplyr, duckplyr data frames are "eager" by default.
To avoid unwanted expensive computation, they can be converted to "lazy" duckplyr frames
on which dplyr::collect()
needs to be called explicitly.
as_duck_tbl()
converts a data frame or a dplyr lazy table to a duckplyr data frame.
This is a generic function that can be overridden for custom classes.
is_duck_tbl()
returns TRUE
if x
is a duckplyr data frame.
duck_tbl(..., .lazy = FALSE) as_duck_tbl(x, ..., .lazy = FALSE) is_duck_tbl(x)
duck_tbl(..., .lazy = FALSE) as_duck_tbl(x, ..., .lazy = FALSE) is_duck_tbl(x)
... |
For |
.lazy |
Logical, whether to create a lazy duckplyr frame.
If |
x |
The object to convert or to test. |
Set the DUCKPLYR_FALLBACK_INFO
and DUCKPLYR_FORCE
environment variables
for more control over the behavior, see config for more details.
For duck_tbl()
and as_duck_tbl()
, an object with the following classes:
"lazy_duckplyr_df"
if .lazy
is TRUE
"duckplyr_df"
Classes of a tibble::tibble
For is_duck_tbl()
, a scalar logical.
x <- duck_tbl(a = 1) x library(dplyr) x %>% mutate(b = 2) x$a y <- duck_tbl(a = 1, .lazy = TRUE) y try(length(y$a)) length(collect(y)$a)
x <- duck_tbl(a = 1) x library(dplyr) x %>% mutate(b = 2) x$a y <- duck_tbl(a = 1, .lazy = TRUE) y try(length(y$a)) length(collect(y)$a)
This is a method for the dplyr::explain()
generic.
This is a generic function which gives more details about an object
than print()
, and is more focused on human readable output than str()
.
## S3 method for class 'duckplyr_df' explain(x, ...)
## S3 method for class 'duckplyr_df' explain(x, ...)
x |
An object to explain |
... |
Other parameters possibly used by generic |
lahman_s <- dbplyr::lahman_sqlite() batting <- tbl(lahman_s, "Batting") explain(batting)
lahman_s <- dbplyr::lahman_sqlite() batting <- tbl(lahman_s, "Batting") explain(batting)
The duckplyr package aims at providing a fully compatible drop-in replacement for dplyr. To achieve this, only a carefully selected subset of dplyr's operations, R functions, and R data types are implemented. Whenever duckplyr encounters an incompatibility, it falls back to dplyr.
To assist future development, the fallback situations can be logged to the console or to a local file and uploaded for analysis. By default, duckplyr will not log or upload anything. The functions and environment variables on this page control the process.
fallback_sitrep()
prints the current settings for fallback logging and uploading,
the number of reports ready for upload, and the location of the logs.
fallback_review()
prints the available reports for review to the console.
fallback_upload()
uploads the available reports to a central server for analysis.
The server is hosted on AWS and the reports are stored in a private S3 bucket.
Only authorized personnel have access to the reports.
fallback_purge()
deletes some or all available reports.
fallback_sitrep() fallback_review(oldest = NULL, newest = NULL, detail = TRUE) fallback_upload(oldest = NULL, newest = NULL, strict = TRUE) fallback_purge(oldest = NULL, newest = NULL)
fallback_sitrep() fallback_review(oldest = NULL, newest = NULL, detail = TRUE) fallback_upload(oldest = NULL, newest = NULL, strict = TRUE) fallback_purge(oldest = NULL, newest = NULL)
oldest , newest
|
The number of oldest or newest reports to review. If not specified, all reports are dispayed. |
detail |
Print the full content of the reports.
Set to |
strict |
If |
Logging and uploading are both opt-in. By default, for logging, a message is printed to the console for the first time in a session and then once every 8 hours.
The following environment variables control the logging and uploading:
DUCKPLYR_FALLBACK_COLLECT
controls logging, set it
to 1 or greater to enable logging.
If the value is 0, logging is disabled.
Future versions of duckplyr may start logging additional data
and thus require a higher value to enable logging.
Set to 99 to enable logging for all future versions.
Use usethis::edit_r_environ()
to edit the environment file.
DUCKPLYR_FALLBACK_VERBOSE
controls printing, set it
to TRUE
or FALSE
to enable or disable printing.
If the value is TRUE
, a message is printed to the console
for each fallback situation.
This setting is only relevant if logging is enabled.
DUCKPLYR_FALLBACK_AUTOUPLOAD
controls uploading, set it
to 1 or greater to enable uploading.
If the value is 0, uploading is disabled.
Currently, uploading is active if the value is 1 or greater.
Future versions of duckplyr may start logging additional data
and thus require a higher value to enable uploading.
Set to 99 to enable uploading for all future versions.
Use usethis::edit_r_environ()
to edit the environment file.
DUCKPLYR_FALLBACK_LOG_DIR
controls the location of the logs.
It must point to a directory (existing or not) where the logs will be written.
By default, logs are written to a directory in the user's cache directory
as returned by tools::R_user_dir("duckplyr", "cache")
.
All code related to fallback logging and uploading is in the
fallback.R
and
telemetry.R
files.
fallback_sitrep()
fallback_sitrep()
This is a method for the dplyr::select()
generic.
See "Fallbacks" section for differences in implementation.
The filter()
function is used to subset a data frame,
retaining all rows that satisfy your conditions.
To be retained, the row must produce a value of TRUE
for all conditions.
Note that when a condition evaluates to NA
the row will be dropped,
unlike base subsetting with [
.
## S3 method for class 'duckplyr_df' filter(.data, ..., .by = NULL, .preserve = FALSE)
## S3 method for class 'duckplyr_df' filter(.data, ..., .by = NULL, .preserve = FALSE)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< |
.by |
< |
.preserve |
Relevant when the |
You cannot use filter.duckplyr_df
with no filter conditions,
nor for a grouped operation (if .by
is set).
If you do the code will fall back to dplyr::filter()
without any error.
filter(mtcars, mpg > 30)
filter(mtcars, mpg > 30)
Provides a copy of nycflights13::flights
that is compatible with duckplyr,
as a tibble.
Call as_duck_tbl()
to enable duckplyr operations.
flights_df()
flights_df()
flights_df()
flights_df()
This is a method for the dplyr::full_join()
generic.
See "Fallbacks" section for differences in implementation.
A full_join()
keeps all observations in x
and y
.
## S3 method for class 'duckplyr_df' full_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", relationship = NULL )
## S3 method for class 'duckplyr_df' full_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", relationship = NULL )
x , y
|
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
suffix |
If there are non-joined duplicate variables in |
... |
Other parameters passed onto methods. |
keep |
Should the join keys from both
|
na_matches |
Should two |
multiple |
Handling of rows in
|
relationship |
Handling of the expected relationship between the keys of
|
You cannot use full_join.duckplyr_df
for an implicit cross join,
for a value of the multiple
argument that isn't the default "all"
.
If you do the code will fall back to dplyr::full_join()
without any error.
library("dplyr") full_join(band_members, band_instruments)
library("dplyr") full_join(band_members, band_instruments)
This is a method for the head()
generic.
See "Fallbacks" section for differences in implementation.
Return the first rows of a data.frame
## S3 method for class 'duckplyr_df' head(x, n = 6L, ...)
## S3 method for class 'duckplyr_df' head(x, n = 6L, ...)
x |
A data.frame |
n |
A positive integer, how many rows to return. |
... |
Not used yet. |
You cannot use head.duckplyr_df
with a negative n
.
If you do the code will fall back to head()
without any error.
head(mtcars, 2)
head(mtcars, 2)
This is a method for the dplyr::inner_join()
generic.
See "Fallbacks" section for differences in implementation.
An inner_join()
only keeps observations from x
that have a matching key in y
.
## S3 method for class 'duckplyr_df' inner_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL )
## S3 method for class 'duckplyr_df' inner_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL )
x , y
|
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
suffix |
If there are non-joined duplicate variables in |
... |
Other parameters passed onto methods. |
keep |
Should the join keys from both
|
na_matches |
Should two |
multiple |
Handling of rows in
|
unmatched |
How should unmatched keys that would result in dropped rows be handled?
|
relationship |
Handling of the expected relationship between the keys of
|
You cannot use inner_join.duckplyr_df
for an implicit crossjoin,
for a value of the multiple
argument that isn't the default "all"
.
for a value of the unmatched
argument that isn't the default "drop"
.
If you do the code will fall back to dplyr::inner_join()
without any error.
library("dplyr") inner_join(band_members, band_instruments)
library("dplyr") inner_join(band_members, band_instruments)
This is a method for the dplyr::intersect()
generic.
See "Fallbacks" section for differences in implementation.
intersect(x, y)
finds all rows in both x
and y
.
## S3 method for class 'duckplyr_df' intersect(x, y, ...)
## S3 method for class 'duckplyr_df' intersect(x, y, ...)
x , y
|
Pair of compatible data frames. A pair of data frames is compatible if they have the same column names (possibly in different orders) and compatible types. |
... |
These dots are for future extensions and must be empty. |
You cannot use intersect.duckplyr_df
if column names are duplicated in one of the tables
if column names are different in both tables.
If you do the code will fall back to dplyr::intersect()
without any error.
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) intersect(df1, df2)
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) intersect(df1, df2)
Before a result is computed, it is specified as a "relation" object. This function retrieves this object for the last computation that led to the materialization of a data frame.
last_rel()
last_rel()
A duckdb "relation" object, or NULL
if no computation has been
performed yet.
This is a method for the dplyr::left_join()
generic.
See "Fallbacks" section for differences in implementation.
A left_join()
keeps all observations in x
.
## S3 method for class 'duckplyr_df' left_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL )
## S3 method for class 'duckplyr_df' left_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL )
x , y
|
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
suffix |
If there are non-joined duplicate variables in |
... |
Other parameters passed onto methods. |
keep |
Should the join keys from both
|
na_matches |
Should two |
multiple |
Handling of rows in
|
unmatched |
How should unmatched keys that would result in dropped rows be handled?
|
relationship |
Handling of the expected relationship between the keys of
|
You cannot use left_join.duckplyr_df
for an implicit cross join,
for a value of the multiple
argument that isn't the default "all"
.
for a value of the unmatched
argument that isn't the default "drop"
.
If you do the code will fall back to dplyr::left_join()
without any error.
library("dplyr") left_join(band_members, band_instruments)
library("dplyr") left_join(band_members, band_instruments)
After calling methods_overwrite()
, all dplyr methods are redirected to duckplyr
for the duraton of the session, or until a call to methods_restore()
.
The methods_overwrite()
function is called automatically when the package is loaded
if the environment variable DUCKPLYR_METHODS_OVERWRITE
is set to TRUE
.
methods_overwrite() methods_restore()
methods_overwrite() methods_restore()
Called for their side effects.
tibble(a = 1:3) %>% mutate(b = a + 1) methods_overwrite() tibble(a = 1:3) %>% mutate(b = a + 1) methods_restore() tibble(a = 1:3) %>% mutate(b = a + 1)
tibble(a = 1:3) %>% mutate(b = a + 1) methods_overwrite() tibble(a = 1:3) %>% mutate(b = a + 1) methods_restore() tibble(a = 1:3) %>% mutate(b = a + 1)
This is a method for the dplyr::mutate()
generic.
mutate()
creates new columns that are functions of existing variables.
It can also modify (if the name is the same as an existing column)
and delete columns (by setting their value to NULL
).
## S3 method for class 'duckplyr_df' mutate( .data, ..., .by = NULL, .keep = c("all", "used", "unused", "none"), .before = NULL, .after = NULL )
## S3 method for class 'duckplyr_df' mutate( .data, ..., .by = NULL, .keep = c("all", "used", "unused", "none"), .before = NULL, .after = NULL )
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< The value can be:
|
.by |
< |
.keep |
Control which columns from
|
.before , .after
|
< |
library("duckplyr") df <- data.frame(x = c(1, 2), row.names = c("a", "b")) df <- mutate(df, y = 2) df
library("duckplyr") df <- data.frame(x = c(1, 2), row.names = c("a", "b")) df <- mutate(df, y = 2) df
The constructor and generics described here define a class that helps separating dplyr's user interface from the actual underlying operations. In the longer term, this will help packages that implement the dplyr interface (such as dbplyr, dtplyr, arrow and similar) to focus on the core details of their functionality, rather than on the intricacies of dplyr's user interface.
new_relational()
constructs an object of class "relational"
.
Users are encouraged to provide the class
argument.
The typical use case will be to create a wrapper function.
rel_to_df()
extracts a data frame representation from a relational object,
to be used by dplyr::collect()
.
rel_filter()
keeps rows that match a predicate,
to be used by dplyr::filter()
.
rel_project()
selects columns or creates new columns,
to be used by dplyr::select()
, dplyr::rename()
,
dplyr::mutate()
, dplyr::relocate()
, and others.
rel_aggregate()
combines several rows into one,
to be used by dplyr::summarize()
.
rel_order()
reorders rows by columns or expressions,
to be used by dplyr::arrange()
.
rel_join()
joins or merges two tables,
to be used by dplyr::left_join()
, dplyr::right_join()
,
dplyr::inner_join()
, dplyr::full_join()
, dplyr::cross_join()
,
dplyr::semi_join()
, and dplyr::anti_join()
.
rel_limit()
limits the number of rows in a table,
to be used by utils::head()
.
rel_distinct()
only keeps the distinct rows in a table,
to be used by dplyr::distinct()
.
rel_set_intersect()
returns rows present in both tables,
to be used by generics::intersect()
.
rel_set_diff()
returns rows present in any of both tables,
to be used by generics::setdiff()
.
rel_set_symdiff()
returns rows present in any of both tables,
to be used by dplyr::symdiff()
.
rel_union_all()
returns rows present in any of both tables,
to be used by dplyr::union_all()
.
rel_explain()
prints an explanation of the plan
executed by the relational object.
rel_alias()
returns the alias name for a relational object.
rel_set_alias()
sets the alias name for a relational object.
rel_names()
returns the column names as character vector,
to be used by colnames()
.
new_relational(..., class = NULL) rel_to_df(rel, ...) rel_filter(rel, exprs, ...) rel_project(rel, exprs, ...) rel_aggregate(rel, groups, aggregates, ...) rel_order(rel, orders, ascending, ...) rel_join( left, right, conds, join = c("inner", "left", "right", "outer", "cross", "semi", "anti"), join_ref_type = c("regular", "natural", "cross", "positional", "asof"), ... ) rel_limit(rel, n, ...) rel_distinct(rel, ...) rel_set_intersect(rel_a, rel_b, ...) rel_set_diff(rel_a, rel_b, ...) rel_set_symdiff(rel_a, rel_b, ...) rel_union_all(rel_a, rel_b, ...) rel_explain(rel, ...) rel_alias(rel, ...) rel_set_alias(rel, alias, ...) rel_names(rel, ...)
new_relational(..., class = NULL) rel_to_df(rel, ...) rel_filter(rel, exprs, ...) rel_project(rel, exprs, ...) rel_aggregate(rel, groups, aggregates, ...) rel_order(rel, orders, ascending, ...) rel_join( left, right, conds, join = c("inner", "left", "right", "outer", "cross", "semi", "anti"), join_ref_type = c("regular", "natural", "cross", "positional", "asof"), ... ) rel_limit(rel, n, ...) rel_distinct(rel, ...) rel_set_intersect(rel_a, rel_b, ...) rel_set_diff(rel_a, rel_b, ...) rel_set_symdiff(rel_a, rel_b, ...) rel_union_all(rel_a, rel_b, ...) rel_explain(rel, ...) rel_alias(rel, ...) rel_set_alias(rel, alias, ...) rel_names(rel, ...)
... |
Reserved for future extensions, must be empty. |
class |
Classes added in front of the |
rel , rel_a , rel_b , left , right
|
A relational object. |
exprs |
A list of |
groups |
A list of expressions to group by. |
aggregates |
A list of expressions with aggregates to compute. |
orders |
A list of expressions to order by. |
ascending |
A logical vector describing the sort order. |
conds |
A list of expressions to use for the join. |
join |
The type of join. |
join_ref_type |
The ref type of join. |
n |
The number of rows. |
alias |
the new alias |
new_relational()
returns a new relational object.
rel_to_df()
returns a data frame.
rel_names()
returns a character vector.
All other generics return a modified relational object.
new_dfrel <- function(x) { stopifnot(is.data.frame(x)) new_relational(list(x), class = "dfrel") } mtcars_rel <- new_dfrel(mtcars[1:5, 1:4]) rel_to_df.dfrel <- function(rel, ...) { unclass(rel)[[1]] } rel_to_df(mtcars_rel) rel_filter.dfrel <- function(rel, exprs, ...) { df <- unclass(rel)[[1]] # A real implementation would evaluate the predicates defined # by the exprs argument new_dfrel(df[seq_len(min(3, nrow(df))), ]) } rel_filter( mtcars_rel, list( relexpr_function( "gt", list(relexpr_reference("cyl"), relexpr_constant("6")) ) ) ) rel_project.dfrel <- function(rel, exprs, ...) { df <- unclass(rel)[[1]] # A real implementation would evaluate the expressions defined # by the exprs argument new_dfrel(df[seq_len(min(3, ncol(df)))]) } rel_project( mtcars_rel, list(relexpr_reference("cyl"), relexpr_reference("disp")) ) rel_order.dfrel <- function(rel, exprs, ...) { df <- unclass(rel)[[1]] # A real implementation would evaluate the expressions defined # by the exprs argument new_dfrel(df[order(df[[1]]), ]) } rel_order( mtcars_rel, list(relexpr_reference("mpg")) ) rel_join.dfrel <- function(left, right, conds, join, ...) { left_df <- unclass(left)[[1]] right_df <- unclass(right)[[1]] # A real implementation would evaluate the expressions # defined by the conds argument, # use different join types based on the join argument, # and implement the join itself instead of relaying to left_join(). new_dfrel(dplyr::left_join(left_df, right_df)) } rel_join(new_dfrel(data.frame(mpg = 21)), mtcars_rel) rel_limit.dfrel <- function(rel, n, ...) { df <- unclass(rel)[[1]] new_dfrel(df[seq_len(n), ]) } rel_limit(mtcars_rel, 3) rel_distinct.dfrel <- function(rel, ...) { df <- unclass(rel)[[1]] new_dfrel(df[!duplicated(df), ]) } rel_distinct(new_dfrel(mtcars[1:3, 1:4])) rel_names.dfrel <- function(rel, ...) { df <- unclass(rel)[[1]] names(df) } rel_names(mtcars_rel)
new_dfrel <- function(x) { stopifnot(is.data.frame(x)) new_relational(list(x), class = "dfrel") } mtcars_rel <- new_dfrel(mtcars[1:5, 1:4]) rel_to_df.dfrel <- function(rel, ...) { unclass(rel)[[1]] } rel_to_df(mtcars_rel) rel_filter.dfrel <- function(rel, exprs, ...) { df <- unclass(rel)[[1]] # A real implementation would evaluate the predicates defined # by the exprs argument new_dfrel(df[seq_len(min(3, nrow(df))), ]) } rel_filter( mtcars_rel, list( relexpr_function( "gt", list(relexpr_reference("cyl"), relexpr_constant("6")) ) ) ) rel_project.dfrel <- function(rel, exprs, ...) { df <- unclass(rel)[[1]] # A real implementation would evaluate the expressions defined # by the exprs argument new_dfrel(df[seq_len(min(3, ncol(df)))]) } rel_project( mtcars_rel, list(relexpr_reference("cyl"), relexpr_reference("disp")) ) rel_order.dfrel <- function(rel, exprs, ...) { df <- unclass(rel)[[1]] # A real implementation would evaluate the expressions defined # by the exprs argument new_dfrel(df[order(df[[1]]), ]) } rel_order( mtcars_rel, list(relexpr_reference("mpg")) ) rel_join.dfrel <- function(left, right, conds, join, ...) { left_df <- unclass(left)[[1]] right_df <- unclass(right)[[1]] # A real implementation would evaluate the expressions # defined by the conds argument, # use different join types based on the join argument, # and implement the join itself instead of relaying to left_join(). new_dfrel(dplyr::left_join(left_df, right_df)) } rel_join(new_dfrel(data.frame(mpg = 21)), mtcars_rel) rel_limit.dfrel <- function(rel, n, ...) { df <- unclass(rel)[[1]] new_dfrel(df[seq_len(n), ]) } rel_limit(mtcars_rel, 3) rel_distinct.dfrel <- function(rel, ...) { df <- unclass(rel)[[1]] new_dfrel(df[!duplicated(df), ]) } rel_distinct(new_dfrel(mtcars[1:3, 1:4])) rel_names.dfrel <- function(rel, ...) { df <- unclass(rel)[[1]] names(df) } rel_names(mtcars_rel)
These functions provide a backend-agnostic way to construct expression trees built of column references, constants, and functions. All subexpressions in an expression tree can have an alias.
new_relexpr()
constructs an object of class "relational_relexpr"
.
It is used by the higher-level constructors,
users should rarely need to call it directly.
relexpr_reference()
constructs a reference to a column.
relexpr_constant()
wraps a constant value.
relexpr_function()
applies a function.
The arguments to this function are a list of other expression objects.
relexpr_comparison()
wraps a comparison expression.
relexpr_window()
applies a function over a window,
similarly to the SQL OVER
clause.
relexpr_set_alias()
assigns an alias to an expression.
new_relexpr(x, class = NULL) relexpr_reference(name, rel = NULL, alias = NULL) relexpr_constant(val, alias = NULL) relexpr_function(name, args, alias = NULL) relexpr_comparison(cmp_op, exprs) relexpr_window( expr, partitions, order_bys = list(), offset_expr = NULL, default_expr = NULL, alias = NULL ) relexpr_set_alias(expr, alias = NULL)
new_relexpr(x, class = NULL) relexpr_reference(name, rel = NULL, alias = NULL) relexpr_constant(val, alias = NULL) relexpr_function(name, args, alias = NULL) relexpr_comparison(cmp_op, exprs) relexpr_window( expr, partitions, order_bys = list(), offset_expr = NULL, default_expr = NULL, alias = NULL ) relexpr_set_alias(expr, alias = NULL)
x |
An object. |
class |
Classes added in front of the |
name |
The name of the column or function to reference. |
rel |
The name of the relation to reference. |
alias |
An alias for the new expression. |
val |
The value to use in the constant expression. |
args |
Function arguments, a list of |
cmp_op |
Comparison operator, e.g., |
exprs |
Expressions to compare, a list of |
expr |
An |
partitions |
Partitions, a list of |
order_bys |
which variables to order results by (list). |
offset_expr |
offset relational expression. |
default_expr |
default relational expression. |
an object of class "relational_relexpr"
an object of class "relational_relexpr"
an object of class "relational_relexpr"
an object of class "relational_relexpr"
an object of class "relational_relexpr"
an object of class "relational_relexpr"
relexpr_set_alias( alias = "my_predicate", relexpr_function( "<", list( relexpr_reference("my_number"), relexpr_constant(42) ) ) )
relexpr_set_alias( alias = "my_predicate", relexpr_function( "<", list( relexpr_reference("my_number"), relexpr_constant(42) ) ) )
The following dplyr generics have no counterpart method in duckplyr. If you want to help add a new verb, please refer to our contributing guide https://duckplyr.tidyverse.org/CONTRIBUTING.html#support-new-verbs
For these verbs, duckplyr will fall back to dplyr.
This is a method for the dplyr::pull()
generic.
See "Fallbacks" section for differences in implementation.
pull()
is similar to $
.
It's mostly useful because it looks a little nicer in pipes,
it also works with remote data frames, and it can optionally name the output.
## S3 method for class 'duckplyr_df' pull(.data, var = -1, name = NULL, ...)
## S3 method for class 'duckplyr_df' pull(.data, var = -1, name = NULL, ...)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
var |
A variable specified as:
The default returns the last column (on the assumption that's the column you've created most recently). This argument is taken by expression and supports quasiquotation (you can unquote column names and column locations). |
name |
An optional parameter that specifies the column to be used
as names for a named vector. Specified in a similar manner as |
... |
For use by methods. |
You cannot use pull.duckplyr_df
with a selection that returns no columns:
If you do the code will fall back to dplyr::pull()
without any error.
pull(mtcars, cyl) pull(mtcars, 1)
pull(mtcars, cyl) pull(mtcars, 1)
This is a method for the dplyr::relocate()
generic.
See "Fallbacks" section for differences in implementation.
Use relocate()
to change column positions,
using the same syntax as select()
to make it easy to move blocks of columns at once.
## S3 method for class 'duckplyr_df' relocate(.data, ..., .before = NULL, .after = NULL)
## S3 method for class 'duckplyr_df' relocate(.data, ..., .before = NULL, .after = NULL)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< |
.before , .after
|
< |
You cannot use relocate.duckplyr_df
with a selection that returns no columns:
If you do the code will fall back to dplyr::relocate()
without any error.
df <- tibble(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a") relocate(df, f)
df <- tibble(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a") relocate(df, f)
This is a method for the dplyr::rename()
generic.
See "Fallbacks" section for differences in implementation.
rename()
changes the names of individual variables
using new_name = old_name
syntax.
## S3 method for class 'duckplyr_df' rename(.data, ...)
## S3 method for class 'duckplyr_df' rename(.data, ...)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
For For |
You cannot use rename.duckplyr_df
with a selection that returns no columns:
If you do the code will fall back to dplyr::rename()
without any error.
rename(mtcars, thing = mpg)
rename(mtcars, thing = mpg)
This is a method for the dplyr::right_join()
generic.
See "Fallbacks" section for differences in implementation.
A right_join()
keeps all observations in y
.
## S3 method for class 'duckplyr_df' right_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL )
## S3 method for class 'duckplyr_df' right_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL )
x , y
|
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
suffix |
If there are non-joined duplicate variables in |
... |
Other parameters passed onto methods. |
keep |
Should the join keys from both
|
na_matches |
Should two |
multiple |
Handling of rows in
|
unmatched |
How should unmatched keys that would result in dropped rows be handled?
|
relationship |
Handling of the expected relationship between the keys of
|
You cannot use right_join.duckplyr_df
for an implicit cross join,
for a value of the multiple
argument that isn't the default "all"
.
for a value of the unmatched
argument that isn't the default "drop"
.
If you do the code will fall back to dplyr::right_join()
without any error.
library("dplyr") right_join(band_members, band_instruments)
library("dplyr") right_join(band_members, band_instruments)
This is a method for the dplyr::select()
generic.
See "Fallbacks" section for differences in implementation.
Select (and optionally rename) variables in a data frame,
using a concise mini-language that makes it easy to refer to variables
based on their name (e.g. a:f
selects all columns from a on the left
to f on the right) or type
(e.g. where(is.numeric)
selects all numeric columns).
## S3 method for class 'duckplyr_df' select(.data, ...)
## S3 method for class 'duckplyr_df' select(.data, ...)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< |
You cannot use select.duckplyr_df
with no expression,
nor with a selection that returns no columns:
If you do the code will fall back to dplyr::select()
without any error.
library("duckplyr") select(mtcars, mpg)
library("duckplyr") select(mtcars, mpg)
This is a method for the dplyr::semi_join()
generic.
semi_join()
returns all rows from x with a match in y.
## S3 method for class 'duckplyr_df' semi_join(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never"))
## S3 method for class 'duckplyr_df' semi_join(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never"))
x , y
|
A pair of data frames, data frame extensions (e.g. a tibble), or lazy data frames (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
by |
A join specification created with If To join on different variables between To join by multiple variables, use a
For simple equality joins, you can alternatively specify a character vector
of variable names to join by. For example, To perform a cross-join, generating all combinations of |
copy |
If |
... |
Other parameters passed onto methods. |
na_matches |
Should two |
library(duckplyr) library(dplyr) band_members %>% semi_join(band_instruments)
library(duckplyr) library(dplyr) band_members %>% semi_join(band_instruments)
This is a method for the dplyr::setdiff()
generic.
See "Fallbacks" section for differences in implementation.
setdiff(x, y)
finds all rows in x
that aren't in y
.
## S3 method for class 'duckplyr_df' setdiff(x, y, ...)
## S3 method for class 'duckplyr_df' setdiff(x, y, ...)
x , y
|
Pair of compatible data frames. A pair of data frames is compatible if they have the same column names (possibly in different orders) and compatible types. |
... |
These dots are for future extensions and must be empty. |
You cannot use setdiff.duckplyr_df
if column names are duplicated in one of the tables
if column names are different in both tables.
If you do the code will fall back to dplyr::setdiff()
without any error.
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) setdiff(df1, df2) setdiff(df2, df1)
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) setdiff(df1, df2) setdiff(df2, df1)
Prints statistics on how many calls were handled by DuckDB. The output shows the total number of requests in the current session, split by fallbacks to dplyr and requests handled by duckdb.
stats_show()
stats_show()
Called for its side effect.
stats_show() tibble(a = 1:3) %>% as_duckplyr_df() %>% mutate(b = a + 1) stats_show()
stats_show() tibble(a = 1:3) %>% as_duckplyr_df() %>% mutate(b = a + 1) stats_show()
This is a method for the dplyr::summarise()
generic.
See "Fallbacks" section for differences in implementation.
summarise()
creates a new data frame.
It returns one row for each combination of grouping variables;
if there are no grouping variables,
the output will have a single row summarising all observations in the input.
It will contain one column for each grouping variable
and one column for each of the summary statistics that you have specified.
## S3 method for class 'duckplyr_df' summarise(.data, ..., .by = NULL, .groups = NULL)
## S3 method for class 'duckplyr_df' summarise(.data, ..., .by = NULL, .groups = NULL)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< The value can be:
Returning values with size 0 or >1 was
deprecated as of 1.1.0. Please use |
.by |
< |
.groups |
Grouping structure of the result.
When
In addition, a message informs you of that choice, unless the result is ungrouped,
the option "dplyr.summarise.inform" is set to |
You cannot use summarise.duckplyr_df
with .groups = "rowwise"
.
If you do the code will fall back to dplyr::summarise()
without any error.
summarise(mtcars, mean = mean(disp), n = n())
summarise(mtcars, mean = mean(disp), n = n())
This is a method for the dplyr::symdiff()
generic.
See "Fallbacks" section for differences in implementation.
symdiff(x, y)
computes the symmetric difference,
i.e. all rows in x
that aren't in y
and all rows in y
that aren't in x
.
## S3 method for class 'duckplyr_df' symdiff(x, y, ...)
## S3 method for class 'duckplyr_df' symdiff(x, y, ...)
x , y
|
Pair of compatible data frames. A pair of data frames is compatible if they have the same column names (possibly in different orders) and compatible types. |
... |
These dots are for future extensions and must be empty. |
You cannot use symdiff.duckplyr_df
if column names are duplicated in one of the tables
if column names are different in both tables.
If you do the code will fall back to dplyr::symdiff()
without any error.
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) symdiff(df1, df2)
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) symdiff(df1, df2)
This is a method for the dplyr::transmute()
generic.
See "Fallbacks" section for differences in implementation.
transmute()
creates a new data frame containing only the specified computations.
It's superseded because you can perform the same job with mutate(.keep = "none")
.
## S3 method for class 'duckplyr_df' transmute(.data, ...)
## S3 method for class 'duckplyr_df' transmute(.data, ...)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< The value can be:
|
You cannot use transmute.duckplyr_df
with a selection that returns no columns:
If you do the code will fall back to dplyr::transmute()
without any error.
library("duckplyr") transmute(mtcars, mpg2 = mpg*2)
library("duckplyr") transmute(mtcars, mpg2 = mpg*2)
This is a method for the dplyr::union_all()
generic.
See "Fallbacks" section for differences in implementation.
union_all(x, y)
finds all rows in either x or y, including duplicates.
## S3 method for class 'duckplyr_df' union_all(x, y, ...)
## S3 method for class 'duckplyr_df' union_all(x, y, ...)
x , y
|
Pair of compatible data frames. A pair of data frames is compatible if they have the same column names (possibly in different orders) and compatible types. |
... |
These dots are for future extensions and must be empty. |
You cannot use union_all.duckplyr_df
if column names are duplicated in one of the tables
if column names are different in both tables.
If you do the code will fall back to dplyr::union_all()
without any error.
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) union_all(df1, df2)
df1 <- tibble(x = 1:3) df2 <- tibble(x = 3:5) union_all(df1, df2)