-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge05-solution.R
More file actions
118 lines (106 loc) · 2.76 KB
/
Copy pathchallenge05-solution.R
File metadata and controls
118 lines (106 loc) · 2.76 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# MASTER PIPELINE HANS LOG DATA ANALYSIS
# author: Sebastian Sauer
# setup -------------------------------------------------------------------
library("targets")
library("tarchetypes")
tar_option_set(
packages = c(
"data.table",
"dplyr",
"purrr",
"readr",
"tidyr",
"collapse",
"stringr",
"lubridate"
)
)
options(lubridate.week.start = 1)
tar_source("funs")
# START OF PIPELINE -------------------------------------------------------
## import data -------------------------------------------------------------
list(
tar_target(config_file, "config.yaml", format = "file"),
tar_target(config, read_yaml(config_file), packages = "yaml"),
tar_target(data_files_list, find_data_files(config), format = "file"),
tar_target(data_files_dupes_excluded, exclude_dupes(data_files_list)),
tar_target(
data_imported,
data_files_dupes_excluded |>
import_and_bind_data()
),
## prep data ---------------------------------------------------------------
tar_target(data_prepped,
data_imported |>
prep_data(),
packages = "janitor"
),
tar_target(data_all_fct,
data_prepped |>
mutate(across(everything(), as.factor)),
packages = "collapse"
),
tar_target(visitduration,
data_prepped |>
)
tar_target(
test_unique_idvisit,
check_unique_ids(data_prepped)
),
tar_target(
data_wide_slim,
data_all_fct |> extract_cols()
),
tar_target(
course_and_uni_per_visit,
data_wide_slim |> extract_course_role_university_of_visit()
),
## pivot longer ------------------------------------------------------------
tar_target(data_long,
data_all_fct |> longify_data(),
packages = c("data.table", "assertthat", "tibble")
),
tar_target(data_separated,
slimify_nona_data(data_long),
packages = c("dplyr", "tidyr", "collapse")
),
tar_target(
data_separated_filtered,
data_separated |>
filter_column_type()
),
## count stuff per visit -------------------------------------------------
# number of visits in total:
tar_target(
n_visits,
data_long |>
pull(idvisit) |>
unique() |>
length()
),
# count number of actions per visit:
tar_target(
n_action,
data_separated_filtered |>
group_by(idvisit) |>
summarise(nr_max = max(nr))
),
# count number of action per unique visitor:
tar_target(
n_action_fingerprint,
data_separated_filtered |>
group_by(fingerprint) |>
summarise(nr_max = max(nr))
),
tar_target(
n_action_lt_500,
n_action |>
filter(nr_max != 499)
),
tar_target(
n_action_lt_500_fingerprint,
n_action_fingerprint |>
filter(nr_max != 499)
)
# END OF PIPELINE ---------------------------------------------------------
)