-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path_common.R
54 lines (48 loc) · 1.11 KB
/
_common.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
set.seed(42)
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
cache = FALSE,
echo = FALSE,
# out.width = "70%",
# fig.align = 'center',
# fig.width = 6,
# fig.asp = 0.618,
fig.show = "hold"
)
options(dplyr.print_min = 6, dplyr.print_max = 6)
options(crayon.enabled = FALSE)
library(tidyverse)
library(here)
library(cowplot)
library(patchwork)
theme_set(theme_cowplot(12))
close_elts <- function(x) x / sum(x)
# Create a pdf from an svg with inkscape
# svg_path should be relative to project root
svg_to_pdf <- function(svg_path) {
fig_path <- fs::path(
'figures', 'export-pdf',
fs::path_ext_set(svg_path, 'pdf')
)
args <- c(
"--export-area-page",
"--export-type=pdf",
str_c("--export-filename=", fig_path),
svg_path
)
system2("inkscape", args = args)
fig_path
}
# include an svg file as a figure
include_svg <- function(svg_path) {
if (knitr::is_html_output()) {
fig_path <- svg_path
} else if (knitr::is_latex_output()) {
fig_path <- svg_to_pdf(svg_path)
} else {
# For word docs
fig_path <- svg_path
}
knitr::include_graphics(fig_path)
}