-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_cohortBuilder.R
49 lines (42 loc) · 1.18 KB
/
02_cohortBuilder.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(magrittr)
librarian_source <- cohortBuilder::set_source(
cohortBuilder::as.tblist(librarian)
)
## Alternativly
# Just create tblist from dataframes
# cohortBuilder::tblist(iris, cars)
coh <- librarian_source %>%
cohortBuilder::cohort(
cohortBuilder::step(
cohortBuilder::filter(
"discrete", id = "author", dataset = "books",
variable = "author", value = "Dan Brown", active = TRUE
),
cohortBuilder::filter(
"range", id = "copies", dataset = "books",
variable = "copies", range = c(5, 10), active = TRUE
),
cohortBuilder::filter(
"date_range", id = "registered", dataset = "borrowers",
variable = "registered", range = c(as.Date("2010-01-01"), Inf),
active = TRUE
)
)
) |>
cohortBuilder::run
cohortBuilder::get_data(coh)
# Update filters
cohortBuilder::update_filter(
coh, step_id = 1, filter_id = "copies",
range = c(0, 10)
)
# Run cohort
cohortBuilder::run(coh)
cohortBuilder::get_data(coh)
# You can also interact with cohort as it's R6 class
cohortBuilder::update_filter(
coh, step_id = 1, filter_id = "copies",
range = c(5, 10)
)
coh$run_flow()
cohortBuilder::get_data(coh)