-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflextable_pdf.Rmd
181 lines (157 loc) · 4.61 KB
/
flextable_pdf.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---
title: "flextable package"
subtitle: "a grammar to produce tabular reporting from R"
date: "2019-07-10"
author: "Quentin Fazilleau"
output:
xaringan::moon_reader:
css: ['default', 'static/ardata-remark.css']
---
```{r setup, include=FALSE, message = FALSE, warning = FALSE}
knitr::opts_chunk$set(echo = TRUE, dev.args=list(bg='transparent', pointsize=10))
library(flextable)
library(officer)
library(magrittr)
```
````{r, eval = TRUE, echo = FALSE}
# Quelques functions dont j'aurais besoin durant la présentation
# Je defini un theme pour la presentation
theme_doc <- function(x) {
if (!inherits(x, "flextable"))
stop("theme_box supports only flextable objects.")
x <- border_remove(x)
std_border <- fp_border(width = 4, color = "white")
x <- align(x, align = "center", part = "all")
x <- font(x, fontname = "Courier", part = "all")
x <- bg(x, bg = "#eb5555", part = "header")
x <- bg(x, bg = "#475f77", part = "body")
x <- bg(x, bg = "#1bbbda", part = "footer")
x <- color(x, color = "white", part = "all")
x <- fontsize(x, size = 13, part = "all")
x <- border_outer(x, part="all", border = std_border )
x <- border_inner_h(x, border = std_border, part="all")
x <- border_inner_v(x, border = std_border, part="all")
x <- autofit(x)
x
}
theme_doc2 <- function(x) {
if (!inherits(x, "flextable"))
stop("theme_box supports only flextable objects.")
x <- border_remove(x)
x <- theme_doc(x)
x <- colformat_num(
x = x,
col_keys = setdiff(x$col_keys, "Species"),
digits = 1
)
x <- autofit(x)
x
}
theme_atp <- function(x) {
if (!inherits(x, "flextable"))
stop("theme_box supports only flextable objects.")
blue_roboto <- fp_text(
color = "#00aeef",
font.family = "Roboto",
font.size = 12
)
border_remove(x) %>%
style(
part = "header",
pr_t = blue_roboto
) %>%
set_formatter(
Percentage = function(x) paste0(sprintf("%.02f", x), "%")
) %>%
colformat_int(
col_keys = setdiff(x$col_keys, c("Rank", "Player", "Percentage", "head", "link", "flag")),
big.mark = ","
) %>%
border_inner(part = "body", border = fp_border(color = "#f1f1f1")) %>%
align(
j = setdiff(x$col_keys, "Player"),
align = "center"
) %>%
padding(j = "Player", padding.bottom = 0) %>%
bg(part = "header", bg = "#f1f1f1") %>%
add_header_lines(values = "Career Service Games Won On Grass From All Countries") %>%
color(i = 1, color = "#1f2223", part = "header") %>%
bold(i = 1, bold = TRUE, part = "header") %>%
fontsize(i = 1, size = 12, part = "header") %>%
add_footer_lines(values = c("", "Source : https://www.atptour.com/en/stats/")) %>%
footnote(
j = 5, ref_symbols = c("*"),
value = as_paragraph(
c("Matches before Wimbledon 2019 starts")
),
part = "header"
) %>%
italic(part = "footer") %>%
width(j = ~ Player, width = 3)
}
misc_formatting <- function(x) {
if (!inherits(x, "flextable"))
stop("theme_box supports only flextable objects.")
x <- x %>%
colformat_num("Wind", digits = 1) %>%
theme_alafoli() %>%
bold(j = "Wind") %>%
color(i = ~ Wind > 12, j = "Wind", color = "#17a589") %>%
color(i = ~ Wind < 12, j = "Wind", color = "#ca6f1e")
x
}
pre <- function(x, i = NULL, j = NULL, part = "body") {
if (!inherits(x, "flextable"))
stop("theme_box supports only flextable objects.")
x <- style(
x,
i = i,
j = j,
part = part,
pr_t = fp_text(
font.family = "Courier",
shading.color = "#EFEFEF",
color = "#23527c"
)
)
x
}
theme_outputs <- function(x) {
if (!inherits(x, "flextable"))
stop("theme_box supports only flextable objects.")
x <- border_remove(x) %>%
font(part = "all", fontname = "Roboto") %>%
style(part = "header", pr_t = fp_text(font.size = 12, bold = TRUE)) %>%
border_inner_h(part = "body", border = fp_border(color = "#dddddd", width = 1)) %>%
hline_bottom(part = "header", border = fp_border(color = "#dddddd", width = 2)) %>%
set_header_labels(values = c(output = "R Markdown output", pandoc = "pandoc version")) %>%
align(j = ~ comment, align = "center") %>%
pre(j = ~ output)
x
}
````
```{r child = 'motivations_2.Rmd'}
```
```{r child = 'history.Rmd'}
```
```{r child = 'flextable_anatomy.Rmd'}
```
```{r child = 'selectors.Rmd'}
```
```{r child = 'format.Rmd'}
```
```{r child = 'cell_merging.Rmd'}
```
```{r child = 'header_footer_2.Rmd'}
```
```{r child = 'compose_presentation.Rmd'}
```
```{r child = 'compose_example.Rmd'}
```
```{r child = 'outputs_2.Rmd'}
```
```{r child = 'shiny_2.Rmd'}
```
---
</br></br></br>
<img src = "./static/img/flextable.png" class = "img_center"/>