Skip to content

Commit 687b672

Browse files
committed
fix rstudio#790: make sure unused arguments are discarded when they are passed to the base format
1 parent 9b3562e commit 687b672

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# CHANGES IN bookdown VERSION 0.17
22

3+
## BUG FIXES
34

5+
- For output formats like `pdf_book`, unused arguments passed to `base_format` will be discarded (thanks, @jooyoungseo, #790).
46

57
# CHANGES IN bookdown VERSION 0.16
68

R/html.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ html_chapters = function(
5454
base_format = rmarkdown::html_document, split_bib = TRUE, page_builder = build_chapter,
5555
split_by = c('section+number', 'section', 'chapter+number', 'chapter', 'rmd', 'none')
5656
) {
57-
base_format = get_base_format(base_format)
58-
config = base_format(
57+
config = get_base_format(base_format, list(
5958
toc = toc, number_sections = number_sections, fig_caption = fig_caption,
6059
self_contained = FALSE, lib_dir = lib_dir,
6160
template = template, pandoc_args = pandoc_args2(pandoc_args), ...
62-
)
61+
))
6362
split_by = match.arg(split_by)
6463
post = config$post_processor # in case a post processor have been defined
6564
config$post_processor = function(metadata, input, output, clean, verbose) {
@@ -126,10 +125,9 @@ tufte_html_book = function(...) {
126125
html_document2 = function(
127126
..., number_sections = TRUE, pandoc_args = NULL, base_format = rmarkdown::html_document
128127
) {
129-
base_format = get_base_format(base_format)
130-
config = base_format(
128+
config = get_base_format(base_format, list(
131129
..., number_sections = number_sections, pandoc_args = pandoc_args2(pandoc_args)
132-
)
130+
))
133131
post = config$post_processor # in case a post processor have been defined
134132
config$post_processor = function(metadata, input, output, clean, verbose) {
135133
if (is.function(post)) output = post(metadata, input, output, clean, verbose)

R/latex.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ pdf_book = function(
3636
base_format = rmarkdown::pdf_document, toc_unnumbered = TRUE,
3737
toc_appendix = FALSE, toc_bib = FALSE, quote_footer = NULL, highlight_bw = FALSE
3838
) {
39-
base_format = get_base_format(base_format)
40-
config = base_format(
39+
config = get_base_format(base_format, list(
4140
toc = toc, number_sections = number_sections, fig_caption = fig_caption,
4241
pandoc_args = pandoc_args2(pandoc_args), ...
43-
)
42+
))
4443
config$pandoc$ext = '.tex'
4544
post = config$post_processor # in case a post processor have been defined
4645
config$post_processor = function(metadata, input, output, clean, verbose) {

R/utils.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ set_opts_knit = function(config) {
3434
config
3535
}
3636

37-
get_base_format = function(format) {
38-
if (is.character(format)) {
39-
format = eval(parse(text = format))
40-
}
37+
get_base_format = function(format, options = list()) {
38+
if (is.character(format)) format = eval(parse(text = format))
4139
if (!is.function(format)) stop('The output format must be a function')
42-
format
40+
# make sure named elements in `options` have corresponding named arguments in
41+
# the format function, unless the function has the ... argument
42+
nms = names(formals(format))
43+
if (!('...' %in% nms)) options = options[names(options) %in% c(nms, '')]
44+
do.call(format, options)
4345
}
4446

4547
load_config = function() {

R/word.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ markdown_document2 = function(
55
) {
66
from = rmarkdown::from_rmarkdown(fig_caption, md_extensions)
77

8-
base_format = get_base_format(base_format)
9-
config = base_format(
8+
config = get_base_format(base_format, list(
109
fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ...
11-
)
10+
))
1211
pre = config$pre_processor
1312
config$pre_processor = function(metadata, input_file, ...) {
1413
# Pandoc does not support numbered sections for Word, so figures/tables have

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy