-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.R
More file actions
70 lines (60 loc) · 2.36 KB
/
Copy pathsetup.R
File metadata and controls
70 lines (60 loc) · 2.36 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
# All Read codes in tibble
#### load libraries ####
library(dplyr)
library(stringr)
library(readr)
library(readxl)
library(tidyr)
library(xtable)
opcrd_analysis_path <- "/Users/elsiehorne/Docs/opcrd_analysis/read_codes"
source('map_functions.R')
rctctv3map <- read_table2("nhs_datamigration_29/Mapping Tables/Updated/Clinically Assured/rctctv3map_uk_20200401000001.txt")
ctv3rctmap <- read_table2("nhs_datamigration_29/Mapping Tables/Updated/Clinically Assured/ctv3rctmap_uk_20200401000002.txt")
rctermsctmap <- read_delim("nhs_datamigration_29/Mapping Tables/Updated/Not Clinically Assured/rctermsctmap_uk_20200401000001.txt",
"\t", escape_double = FALSE, trim_ws = TRUE) %>%
distinct(ReadCode, Term)
#### Functions ####
read_cprd <- function(name) {
# although file name is allergic, the list includes codes for allergic and chronic
if (name == 'rhinitis') name <- 'allergic_rhinitis'
else if (name == 'dermatitis') name <- 'derm_merge'
file <- str_c('lists_in/Kuan2019/CPRD_', name, '.csv')
rc_ <- suppressMessages(read_csv(file)) %>%
select(read_code = `Read code`,
read_term = Descr) %>%
mutate_at('read_code', list(~ str_pad(., width = 5, side = 'right', pad = '.'))) %>%
mutate_at('read_code', list(~ str_extract(., pattern = '^.{5}'))) %>%
distinct()
}
# function for reading code lists from the Nwaru2020 paper
read_nwaru <- function(variable) {
filename <- str_c('lists_in/Nwaru2020/cl_', variable,'_nwaru')
read_table2(file = filename, col_names = FALSE) %>%
pivot_longer(cols = 1:ncol(.)) %>%
transmute(read_code = str_remove_all(value, '\\"|,'))
}
#### path for latex tables ####
latex_table_path <- '/Users/elsiehorne/Docs/thesis_repo/thesis_tex/tables/rc_'
# xtable single page
print_xtable_single <- function(.data, filename) {
print(.data,
include.colnames = T,
include.rownames = F,
caption.placement = 'top',
file = str_c(latex_table_path, filename),
comment = F,
booktabs = T,
floating = F)
}
# xtable single page
print_xtable_multi <- function(.data, filename) {
print(.data,
include.colnames = T,
include.rownames = F,
caption.placement = 'top',
file = str_c(latex_table_path, filename),
comment = F,
booktabs = T,
tabular.environment = "longtable",
floating = F)
}