-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRunStudy_v2.R
65 lines (56 loc) · 2.28 KB
/
RunStudy_v2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Create zip file
zipName <- paste0(db.name,"_Results_v2")
tempDir <- zipName
tempDirCreated <- FALSE
if (!dir.exists(tempDir)) {
dir.create(tempDir)
tempDirCreated <- TRUE
}
start <- Sys.time()
# Start log
log_file <- paste0(tempDir, "/log.txt")
# Think what to do if already there. Overwrite, append?
logger <- create.logger()
logfile(logger) <- log_file
level(logger) <- "INFO"
# Create table names to use throughout the study
InitialCohortsName <- paste0(table_stem,"_initialcohorts")
BaseCohortsName <- paste0(table_stem,"_basecohorts")
LongCovidCohortsName <- paste0(table_stem,"_lccohorts")
PascCohortsName <- paste0(table_stem,"_pasccohorts")
MedCondCohortsName <- paste0(table_stem,"_mccohorts")
OverlapCohortsCName <- paste0(table_stem,"_overlapccohorts")
OverlapCohortsIPName <- paste0(table_stem,"_overlapipcohorts")
HUCohortsName <- paste0(table_stem,"_hucohorts")
TrajCohortsName <- paste0(table_stem,"_trajcohort")
VaccCohortsName <- paste0(table_stem,"_vacccohorts")
Extrav2CohortsName <- paste0(table_stem,"_extrav2cohorts")
# Create vector with all names
CohortNames <- c(InitialCohortsName, BaseCohortsName, LongCovidCohortsName,
PascCohortsName, MedCondCohortsName, OverlapCohortsCName,
OverlapCohortsIPName, HUCohortsName, TrajCohortsName,
VaccCohortsName, Extrav2CohortsName)
# get functions used throughout this study
source(here::here("functions.R"))
# Read initial cohorts
Initial_cohorts <- CDMConnector::readCohortSet(
here::here("1_InitialCohorts", "Jsons")) %>%
dplyr::mutate(cohort_name = substr(cohort_name, 5, nchar(cohort_name)))
cdm <- cdmFromCon(
db, cdm_database_schema, writeSchema = results_database_schema,
cohortTables = InitialCohortsName)
info(logger, 'COHORTS READ')
# Do extra characterisation analyses
source(here::here("8_Extra", "extraAnalyses_v2.R"))
zip::zip(zipfile = file.path(output.folder, paste0(zipName, ".zip")),
files = list.files(tempDir, full.names = TRUE))
if (tempDirCreated) {
unlink(tempDir, recursive = TRUE)
}
info(logger, 'SAVED RESULTS IN THE OUTPUT FOLDER')
print("Done!")
print("If all has worked, there should now be a zip file with your results
in the output folder to share")
print("Thank you for running the study!")
Sys.time() - start
readLines(log_file)