
Cross join of data frame-like objects DT and i using a DT[i]-style interface to data.table
Source: R/dtjoin_cross.R
dtjoin_cross.RdWrite (and optionally run) data.table code to return the cross join of
two data.frame-like objects using a generalisation of DT[i]
syntax.
The function fjoin_cross provides a more conventional interface
that is recommended over dtjoin_cross for most users and cases.
Arguments
- .DT, .i
data.frame-like objects (plain,data.table, tibble,sf,list, etc.), or else both omitted for a mock join statement with no data.- select, select.DT, select.i
Character vectors of columns to be selected from either input if present (
select) or specifically from one or other (select.DT,select.i).NULL(the default) selects all columns. Use""orNAto select no columns. Join columns are always selected. See Details.- i.home
Whether to treat
.ias the "home" table and.DTas the "foreign" table for column prefixing andindicate. DefaultFALSE, i.e..DTis the "home" table, as in[.data.table.- i.first
Whether to place
.i's columns before.DT's in the join result. The default is to use the value ofi.home, i.e. bring.i's columns to the front if.iis the "home" table.- prefix
A prefix to attach to column names in the "foreign" table that are the same as a column name in the "home" table. The default is
"i."if the "foreign" table is.i(i.homeisFALSE) and"x."if it is.DT(i.homeisTRUE).- i.class
Whether the
classof the output should be based on.iinstead of.DT. The default followsi.home(defaultFALSE). See Details for how outputclassand other attributes are set.- do
Whether to execute the join. Default is
TRUEunless.DTand.iare both omitted/NULL, in which case a mock join statement is produced.- show
Whether to print the code for the join to the console. Default is the opposite of
do. If.DTand.iare both omitted/NULL, mock join code is displayed.- ...
Further arguments (for internal use).
Value
A data.frame, data.table, (grouped) tibble, sf,
or sf-tibble, or else NULL if do is FALSE. See
Details.
Details
Details are as for dtjoin except for remarks about join
columns and matching logic, which do not apply.
See also
See the package-level documentation fjoin for related
functions.
Examples
# data frames
df1 <- data.table::fread(data.table = FALSE, input = "
bread kcal
Brown 150
White 180
Baguette 250
")
df2 <- data.table::fread(data.table = FALSE, input = "
filling kcal
Cheese 200
Pâté 160
")
dtjoin_cross(df1, df2)
#> bread kcal filling i.kcal
#> 1 Brown 150 Cheese 200
#> 2 White 180 Cheese 200
#> 3 Baguette 250 Cheese 200
#> 4 Brown 150 Pâté 160
#> 5 White 180 Pâté 160
#> 6 Baguette 250 Pâté 160