-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
166 lines (141 loc) · 3.88 KB
/
index.Rmd
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
site: bookdown::bookdown_site
title: '`r yaml::read_yaml("_meta.yml")$book_title`'
author: '`r yaml::read_yaml("_meta.yml")$book_author`'
date: "`r format(Sys.Date(), '%d %B %Y')`"
documentclass: article
classoption: 12pt
bibliography: ["book/bib/references.bib", "book/bib/packages.bib"]
link-citations: yes
github-repo: null
---
```{r Setup, message=FALSE, warning=FALSE, include=FALSE}
# Default to show/hide code in output
knitr::opts_chunk$set(echo = FALSE,
message = FALSE,
warning = FALSE,
fig.pos = "tbp",
out.extra = "",
out.width = "100%",
fig.retina = 2,
fig.align = "center")
# knitr and kable/kableExtra options
# set before calling library to ensure correct options by default
options(knitr.kable.NA = '')
options(knitr.table.format = "pipe")
options(kableExtra.auto_format = FALSE)
# Tidyverse packages (remove as appropriate)
#library(magrittr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(purrr)
#library(tibble)
library(stringr)
library(forcats)
library(readr)
#library(readxl)
library(broom)
# other packages
#library(fs)
library(glue)
library(janitor)
library(here)
#library(effectsize)
#library(skimr)
library(ggthemr)
#library(PNWColors) # https://github.com/jakelawlor/pnwcolors
# pal <- PNWColors::pnw_palette(name="Sailboat",n=8,type="discrete")
library(ggtext)
#library(ggsignif)
library(patchwork)
#library(ez)
library(conflicted)
# conflicted::conflict_prefer("cooks.distance.influence.merMod", "car")
conflicted::conflict_prefer("set_names", "purrr")
conflicted::conflict_prefer("filter", "dplyr")
library(knitr)
library(kableExtra)
# set plot theme
ggthemr('greyscale', layout = 'minimal')
# set PDF and word variables to FALSE by default; will be overwritten for
# appropriate output in next chunk or left as-is for working in RStudio
pdf <- FALSE
word <- FALSE
# read chunks in to include from external code sources -
# just remember that at SOME point, anything to be used in the final output MUST
# be imported into the index or src files somewhere - so any data creation/import
# chunks in the external code also need to be read in before their output will work
analysis_files <- list.files(path=here::here("analysis"),
pattern = "^[^_][0-9a-zA-Z-]+.R$", full.names = TRUE)
for (file in analysis_files) {
knitr::read_chunk(file)
}
```
```{r detect-output, include=FALSE}
# detect current knitr rendering format
# will output as 'bookdown::pdf_document', 'bookdown::word_document' etc
fmt <- rmarkdown::all_output_formats(knitr::current_input())[1]
pdf <- grepl("pdf", fmt)
word <- grepl("word", fmt)
git <- grepl("gitbook", fmt)
```
```{r float-spacing}
# if(pdf) {
# plot_default <- knit_hooks$get("plot")
# knit_hooks$set(plot = function(x, options) {
# x <- c("\\vspace{20pt}", plot_default(x, options), "\\vspace{20pt}")
# })
# }
if(pdf) {
knit_hooks$set(floatspacer = function(before, options, envir) {
if (before) {
"\\vspace{20pt}"
} else {
"\\vspace{20pt}"
}
})
} else {
knit_hooks$set(floatspacer = function(before, options, envir) {
if (before) {
""
} else {
""
}
})
}
```
```{r word-tocs, eval=FALSE, include=FALSE}
# if rendering to .docx, include blank pages with headings for
# table of contents and lists of figures/tables/appendices
if(word) {
word_toc <- glue::glue('
\\newpage
::: {{custom-style="Title"}}
Table of Contents
:::
\\newpage
::: {{custom-style="Title"}}
List of Figures
:::
\\newpage
::: {{custom-style="Title"}}
List of Tables
:::
\\newpage
::: {{custom-style="Title"}}
List of Appendices
:::
\\newpage
')
} else {
word_toc <- NULL
}
```
```{r}
if (git) {
knitr::opts_chunk$set(out.width = "50%")
}
```
```{r, child=if (git) here::here('book', 'src', '_preface.Rmd')}
```