forked from OHI-Science/ohimanual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_communicate.R
56 lines (43 loc) · 1.65 KB
/
make_communicate.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
# load libraries ----
library(knitr) # install.packages("knitr")
library(rmarkdown)
library(stringr)
# Also required if you get the pdflatex error: www.tug.org/mactex
# set variables ----
title = 'The Ocean Health Index Communication Guide' ### title??
wd = '~/github/ohimanual/4_communicate'
in_md = c(
# 'Phase_4.md', # currently this file is in 0_orientation; JSL not sure it fits here?
'Outreach_and_Communications.md',
'Communication_and_Outreach_Strategy.md',
'Disseminating_Findings.md',
'Communicate_Results_with_Partners.md',
'Develop_and_Implement_Policies_and_Management_Interventions_that_Respond_to_the_Priorities.md',
'Monitor_and_Re-evaluate_to_Determine_Policy_Effectiveness_and_Set_New_Priorities.md')
# summarzing ending # add some kind of summary
out_md = 'ohi-communicate.md'
# helper functions ----
cat_md = function(
files_md = setdiff(list.files(getwd(), glob2rx('*.md')), out_md),
out_md = '_all_.md'){
if (file.exists(out_md)) unlink(out_md)
cat('---\n', 'title: ', title, '\n---\n\n', sep='', file=out_md, append=T)
for (md in files_md){
cat(paste(c(readLines(md),'',''), collapse='\n'), file=out_md, append=T)
}
}
# concatenate md ----
setwd(wd)
cat_md(in_md, out_md)
pfx = tools::file_path_sans_ext(out_md)
# render pdf ----
render(
out_md,
pdf_document(
toc = T, toc_depth = 3, number_sections = T,
fig_width = 6.5, fig_height = 4.5, fig_crop = TRUE,
fig_caption = T, highlight = "default", template = "default",
keep_tex = F, latex_engine = "pdflatex",
includes = NULL, pandoc_args = NULL),
clean=T, quiet=F,
output_file = paste0(pfx, '.pdf'))