generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_min_max_fu.R
48 lines (38 loc) · 1.51 KB
/
data_min_max_fu.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
################################################################################
# This script:
# - calculates min and max follow-up dates for each subgroup
################################################################################
library(tidyverse)
################################################################################
# create output directories ----
fs::dir_create(here::here("output", "lib"))
################################################################################
# read study parameters
study_parameters <- readr::read_rds(
here::here("analysis", "lib", "study_parameters.rds"))
################################################################################
## read data
# covariates data
data_all <- readr::read_rds(
here::here("output", "data", "data_all.rds"))
################################################################################
# redaction functions
source(here::here("analysis", "functions", "redaction_functions.R"))
################################################################################
data_min_max_fu <- data_all %>%
group_by(subgroup) %>%
summarise(
min_fu_date = min(start_1_date),
max_fu_date = max(end_6_date),
# round total to nereast 7 for disclosure control
n = ceiling_any(n(), to=7),
.groups = "keep"
) %>%
ungroup() %>%
mutate(across(max_fu_date,
~ pmin(as.Date(study_parameters$end_date), .x)))
# data for release
readr::write_csv(
data_min_max_fu,
here::here("output", "lib", "data_min_max_fu.csv")
)