These perform set operations on tracked dataframes. It merges the history
of 2 (or more) dataframes and combines the rows (or columns). It calculates the total number of
resulting rows as {.count.out} in other terms it performs exactly the same
operation as the equivalent dplyr
operation. See dplyr::bind_rows()
,
dplyr::bind_cols()
, dplyr::intersect()
, dplyr::union()
,
dplyr::setdiff()
,dplyr::intersect()
, or dplyr::union_all()
for the
underlying function details.
Arguments
- ...
a collection of tracked data frames to combine Named arguments passed on to
dplyr::bind_cols
.name_repair
One of
"unique"
,"universal"
, or"check_unique"
. Seevctrs::vec_as_names()
for the meaning of these options.
- .messages
a set of glue specs. The glue code can use any global variable, or {.count.out}
- .headline
a glue spec. The glue code can use any global variable, or {.count.out}
Examples
library(dplyr)
library(dtrackr)
# Set operations
people = starwars %>% select(-films, -vehicles, -starships)
chrs = people %>% track("start")
lhs = chrs %>% include_any(
species == "Human" ~ "{.included} humans",
species == "Droid" ~ "{.included} droids"
)
# these are different subsets of the same data
rhs = chrs %>% include_any(
species == "Human" ~ "{.included} humans",
species == "Gungan" ~ "{.included} gungans"
) %>% comment("{.count} gungans & humans")
# Unions
set = bind_rows(lhs,rhs) %>% comment("{.count} 2*human,droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 3 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "79 2*human,droids and gungans"
nrow(set)
#> [1] 79
# not run - display the flowchart:
# set %>% flowchart()
set = union(lhs,rhs) %>% comment("{.count} human,droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "44 human,droids and gungans"
nrow(set)
#> [1] 44
# not run - display the flowchart:
# set %>% flowchart()
set = union_all(lhs,rhs) %>% comment("{.count} 2*human,droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "79 2*human,droids and gungans"
nrow(set)
#> [1] 79
# not run - display the flowchart:
# set %>% flowchart()
# Intersections and differences
set = setdiff(lhs,rhs) %>% comment("{.count} droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "6 droids and gungans"
nrow(set)
#> [1] 6
# not run - display the flowchart:
# set %>% flowchart()
set = intersect(lhs,rhs) %>% comment("{.count} humans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "35 humans"
nrow(set)
#> [1] 35
# not run - display the flowchart:
# set %>% flowchart()