Debian Codegraph @

R/slidy_presentation.R

raw
1 #' Convert to a slidy presentation
2 #'
3 #' Format for converting from R Markdown to a slidy presentation.
4 #'
5 #' See the \href{https://yihui.org/rmarkdown/slidy-presentation.html}{online
6 #' documentation} for additional details on using the \code{slidy_presentation}
7 #' format.
8 #'
9 #' For more information on markdown syntax for presentations see the
10 #' \href{https://pandoc.org/MANUAL.html}{pandoc online documentation}.
11 #' @inheritParams pdf_document
12 #' @inheritParams html_document
13 #' @inheritParams beamer_presentation
14 #' @param duration Duration (in minutes) of the slide deck. This value is used
15 #' to add a countdown timer to the slide footer.
16 #' @param footer Footer text (e.g. organization name and/or copyright)
17 #' @param font_adjustment Increase or decrease the default font size (e.g. -1 or
18 #' +1). You can also manually adjust the font size during the presentation
19 #' using the 'S' (smaller) and 'B' (bigger) keys.
20 #' @param css One or more css files to include.
21 #' @param ... Additional function arguments to pass to the base R Markdown HTML
22 #' output formatter \code{\link{html_document_base}}
23 #' @return R Markdown output format to pass to \code{\link{render}}
24 #' @examples
25 #' \dontrun{
26 #' library(rmarkdown)
27 #'
28 #' # simple invocation
29 #' render("pres.Rmd", slidy_presentation())
30 #'
31 #' # specify an option for incremental rendering
32 #' render("pres.Rmd", slidy_presentation(incremental = TRUE))
33 #' }
34 #' @export
35 slidy_presentation <- function(number_sections = FALSE,
36 incremental = FALSE,
37 slide_level = NULL,
38 duration = NULL,
39 footer = NULL,
40 font_adjustment = 0,
41 fig_width = 8,
42 fig_height = 6,
43 fig_retina = 2,
44 fig_caption = TRUE,
45 dev = 'png',
46 df_print = "default",
47 self_contained = TRUE,
48 highlight = "default",
49 math_method = "default",
50 mathjax = "default",
51 template = "default",
52 css = NULL,
53 includes = NULL,
54 keep_md = FALSE,
55 lib_dir = NULL,
56 md_extensions = NULL,
57 pandoc_args = NULL,
58 extra_dependencies = NULL,
59 ...) {
60
61 # base pandoc options for all reveal.js output
62 args <- c()
63
64 # template path and assets
65 if (identical(template, "default"))
66 template <- pkg_file("rmd/slidy/default.html")
67 if (!is.null(template))
68 args <- c(args, "--template", pandoc_path_arg(template))
69
70 # html dependency for slidy
71 extra_dependencies <- append(
72 extra_dependencies,
73 list(html_dependency_slidy(),
74 html_dependency_slidy_shiny()))
75
76 # incremental
77 if (incremental)
78 args <- c(args, "--incremental")
79
80 # slide level
81 if (!is.null(slide_level))
82 args <- c(args, "--slide-level", slide_level)
83
84 # duration
85 if (!is.null(duration))
86 args <- c(args, pandoc_variable_arg("duration", duration))
87
88 # footer
89 if (!is.null(footer))
90 args <- c(args, pandoc_variable_arg("footer", footer))
91
92 # font size adjustment
93 if (font_adjustment != 0)
94 args <- c(args, pandoc_variable_arg("font-size-adjustment",
95 font_adjustment))
96
97 # content includes
98 args <- c(args, includes_to_pandoc_args(includes))
99
100 # pagedtables
101 if (identical(df_print, "paged")) {
102 extra_dependencies <- append(extra_dependencies,
103 list(html_dependency_pagedtable()))
104 }
105
106 # additional css
107 for (css_file in css)
108 args <- c(args, "--css", pandoc_path_arg(css_file, backslash = FALSE))
109
110 # pre-processor for arguments that may depend on the name of the
111 # the input file (e.g. ones that need to copy supporting files)
112 pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
113 output_dir) {
114
115 # use files_dir as lib_dir if not explicitly specified
116 if (is.null(lib_dir))
117 lib_dir <- files_dir
118
119 # extra args
120 args <- c()
121
122 # highlight
123 if (!is.null(highlight)) highlight <- resolve_highlight(highlight, highlighters())
124 args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
125
126 # return additional args
127 args
128 }
129
130 # return format
131 output_format(
132 knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md, dev),
133 pandoc = pandoc_options(
134 to = "slidy",
135 from = from_rmarkdown(fig_caption, md_extensions),
136 args = args,
137 lua_filters = if (number_sections) pkg_file_lua("number-sections.lua")
138 ),
139 keep_md = keep_md,
140 clean_supporting = self_contained,
141 df_print = df_print,
142 pre_processor = pre_processor,
143 base_format = html_document_base(lib_dir = lib_dir,
144 self_contained = self_contained,
145 math_method = math_method,
146 mathjax = mathjax,
147 bootstrap_compatible = TRUE,
148 pandoc_args = pandoc_args,
149 extra_dependencies = extra_dependencies,
150 ...))
151 }
152
153 html_dependency_slidy <- function() {
154 htmlDependency(
155 name = "slidy",
156 version = "2",
157 src = pkg_file("rmd/slidy/Slidy2"),
158 script = "scripts/slidy.js",
159 stylesheet = "styles/slidy.css"
160 )
161 }
162
163 html_dependency_slidy_shiny <- function() {
164 htmlDependency(
165 name = "slidy_shiny",
166 version = "1",
167 src = pkg_file("rmd/slidy/"),
168 script = "slidy_shiny.js",
169 all_files = FALSE
170 )
171 }