-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_charts_preterm.R
59 lines (49 loc) · 1.78 KB
/
make_charts_preterm.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
# make_charts_preterm.R
#
# Writes selected preterm growth chart series
library(chartdesigner)
library(chartbox)
preterms <- c(
paste0("PJAAN", 25:36), paste0("PJABN", 25:36),
paste0("PMAAN", 25:36), paste0("PMABN", 25:36),
paste0("PJEAN", 25:36),
paste0("PMEAN", 25:36))
solo <-
c(paste0("PJAON", 25:36), paste0("PMAON", 25:36),
paste0("PJAWN", 25:36), paste0("PMAWN", 25:36),
paste0("PJAHN", 25:36), paste0("PMAHN", 25:36),
paste0("PJEHN", 25:36), paste0("PMEHN", 25:36),
paste0("PJEWN", 25:36), paste0("PMEWN", 25:36),
paste0("PJADN", 25:36), paste0("PMADN", 25:36),
paste0("PJEDN", 25:36), paste0("PMEDN", 25:36))
sides <- c(preterms, solo)
# write to chartbox
project <- path.expand("~/package/chartbox/chartbox")
chartbox <- file.path(project, "inst/library/preterm")
for (chartcode in sides) {
outfile <- file.path(chartbox, paste(chartcode, "rds", sep = "."))
g <- growthchart(chartcode, paper = "A4")
saveRDS(g, file = outfile, compress = "xz")
}
# check - reload every file
files <- dir(chartbox)
chartcodes <- unlist(strsplit(files, split = "[.]"))[seq(1, 2 * length(files), 2)]
# check - which sides do not have files?
sides[!sides %in% chartcodes]
# export chart to pdf
pdfdir <- file.path(project, "pdf")
pdf.options(useDingbats = FALSE, colormodel = "srgb", family = "Helvetica")
setpalet <- function(chartcode) {
palettes <- chartbox::palettes
parsed <- chartcatalog::parse_chartcode(chartcode)
palette(palettes[parsed$population,])
}
for (chartcode in chartcodes) {
infile <- file.path(chartbox, paste(chartcode, "rds", sep = "."))
g <- readRDS(file = infile)
filename <- file.path(pdfdir, "preterm", paste(chartcode, "pdf", sep = "."))
pdf(filename, height = 29.7/2.54, width = 21/2.54)
setpalet(chartcode)
grid::grid.draw(g)
dev.off()
}