generated from oxford-pharmacoepi/StudyTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeToRun.R
95 lines (81 loc) · 2.79 KB
/
CodeToRun.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
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
# ADD NECESSARY PACKAGES
#install.packages("renv") # if not already installed, install renv from CRAN
# renv::activate()
renv::restore() # this should prompt you to install the various packages required for the study
library(CDMConnector)
library(DBI)
library(plyr)
library(log4r)
library(dplyr)
library(dbplyr)
library(here)
library(tidyr)
library(CodelistGenerator)
library(DrugUtilisation)
library(ggplot2)
library(xlsx)
library(CohortSymmetry)
library(CohortConstructor)
library(readxl)
# database metadata and connection details -----
# The name/ acronym for the database
db_name <- "...."
# Set output folder location -----
# the path to a folder where the results from this analysis will be saved
output_folder <- here(paste0("Results_", db_name))
if (!dir.exists(output_folder)) {
dir.create(output_folder)
}
# Database connection details -----
# In this study we also use the DBI package to connect to the database
# set up the dbConnect details below
# https://darwin-eu.github.io/CDMConnector/articles/DBI_connection_examples.html
# for more details.
# you may need to install another package for this
# eg for postgres
# db <- dbConnect(
# RPostgres::Postgres(),
# dbname = server_dbi,
# port = port,
# host = host,
# user = user,
# password = password
# )
db <- dbConnect("....")
# The name of the schema that contains the OMOP CDM with patient-level data
cdm_database_schema <- "...."
# The name of the schema where results tables will be created
results_database_schema <- "...."
# Whether or not to run negative/positive control (T/F)
run_controls <- TRUE
# Whether or not to run hypothesis driven (using hypotheses found using previous research)
run_hypothesis_driven <- TRUE
# Whether or not the cohorts for hypothesis-driven approach have been instantiated
hypothesis_cohort_instantiated <- FALSE
# Name of stem outcome table in the result schema where the outcome cohorts will
# be stored.
# Notes:
# - if there is an existing table in your results schema with the same names it
# will be overwritten
# - more than one cohort will be created
# - name must be lower case
stem_table <- "...."
# minimum counts that can be displayed according to data governance
minimum_counts <- 5
# create cdm reference ----
cdm <- CDMConnector::cdmFromCon(
con = db,
cdmSchema = cdm_database_schema,
writeSchema = results_database_schema,
writePrefix = stem_table
)
# check database connection
# running the next line should give you a count of your person table
cdm$person %>%
tally()
# Run the study ------
source(here("RunAnalysis.R"))
# after the study is run you should have a zip folder in your output folder to share
print("Done!")
print("-- If all has worked, there should now be a zip folder with your results in the output folder to share")
print("-- Thank you for running the study!")