Skip to content

Commit

Permalink
rename yaml_front_matter to front_matter because the former is al…
Browse files Browse the repository at this point in the history
…so a function in this package (this is to amend rstudio#1710)
  • Loading branch information
yihui committed Dec 3, 2019
1 parent d8fbf4c commit e4c6234
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,17 @@ render <- function(input,
input_lines <- read_utf8(knit_input)

# read the yaml front matter
yaml_front_matter <- parse_yaml_front_matter(input_lines)
front_matter <- parse_yaml_front_matter(input_lines)

# metadata to be attached to the returned value of render() as an attribute
old_output_metadata <- output_metadata$get()
on.exit(output_metadata$restore(old_output_metadata), add = TRUE)
output_metadata$restore(as.list(yaml_front_matter[['rmd_output_metadata']]))
output_metadata$restore(as.list(front_matter[['rmd_output_metadata']]))

# if this is shiny_prerendered then modify the output format to
# be single-page and to output dependencies to the shiny.dep file
shiny_prerendered_dependencies <- list()
if (requires_knit && is_shiny_prerendered(yaml_front_matter$runtime)) {
if (requires_knit && is_shiny_prerendered(front_matter$runtime)) {

# first validate that the user hasn't passed an already created output_format
if (is_output_format(output_format)) {
Expand Down Expand Up @@ -511,12 +511,7 @@ render <- function(input,
# presume that we're rendering as a static document unless specified
# otherwise in the parameters
runtime <- match.arg(runtime)
if (identical(runtime, "auto")) {
if (!is.null(yaml_front_matter$runtime))
runtime <- yaml_front_matter$runtime
else
runtime <- "static"
}
if (identical(runtime, "auto")) runtime <- front_matter$runtime %||% "static"

# set df_print
context <- render_context()
Expand All @@ -530,7 +525,7 @@ render <- function(input,
# function used to call post_knit handler
call_post_knit_handler <- function() {
if (!is.null(output_format$post_knit)) {
post_knit_extra_args <- output_format$post_knit(yaml_front_matter,
post_knit_extra_args <- output_format$post_knit(front_matter,
knit_input,
runtime)
} else {
Expand Down Expand Up @@ -587,7 +582,7 @@ render <- function(input,
# read root directory from argument (has precedence) or front matter
root_dir <- knit_root_dir
if (is.null(root_dir))
root_dir <- yaml_front_matter$knit_root_dir
root_dir <- front_matter$knit_root_dir
if (!is.null(root_dir))
knitr::opts_knit$set(root.dir = root_dir)

Expand Down Expand Up @@ -667,7 +662,7 @@ render <- function(input,
# make the params available within the knit environment
# (only do this if there are parameters in the front matter
# so we don't require recent knitr for all users)
if (!is.null(yaml_front_matter$params)) {
if (!is.null(front_matter$params)) {

params <- knit_params_get(input_lines, params)

Expand Down Expand Up @@ -703,9 +698,8 @@ render <- function(input,
}, add = TRUE)
}

# make the yaml_front_matter available as 'metadata' within the
# knit environment (unless it is already defined there in which case
# we emit a warning)
# make the front_matter available as 'metadata' within the knit environment
# (unless it is already defined there, in which case we emit a warning)
env <- environment(render)
metadata_this <- env$metadata
do.call("unlockBinding", list("metadata", env))
Expand All @@ -716,7 +710,7 @@ render <- function(input,
env$metadata <- metadata_this
lockBinding("metadata", env)
}, add = TRUE)
env$metadata <- yaml_front_matter
env$metadata <- front_matter

# call onKnit hooks (normalize to list)
sapply(as.list(getHook("rmarkdown.onKnit")), function(hook) {
Expand All @@ -738,7 +732,7 @@ render <- function(input,

perf_timer_stop("knitr")

yaml_front_matter <- yaml_front_matter(input)
front_matter <- yaml_front_matter(input)

# call post_knit handler
output_format$pandoc$args <- call_post_knit_handler()
Expand All @@ -763,7 +757,7 @@ render <- function(input,
if (!(is_pandoc_to_html(output_format$pandoc) ||
identical(tolower(tools::file_ext(output_file)), "html"))) {
if (has_html_dependencies(knit_meta)) {
if (!isTRUE(yaml_front_matter$always_allow_html)) {
if (!isTRUE(front_matter$always_allow_html)) {
stop("Functions that produce HTML output found in document targeting ",
pandoc_to, " output.\nPlease change the output type ",
"of this document to HTML. Alternatively, you can allow\n",
Expand Down Expand Up @@ -811,7 +805,7 @@ render <- function(input,

# call any pre_processor
if (!is.null(output_format$pre_processor)) {
extra_args <- output_format$pre_processor(yaml_front_matter,
extra_args <- output_format$pre_processor(front_matter,
utf8_input,
runtime,
knit_meta,
Expand Down Expand Up @@ -843,7 +837,7 @@ render <- function(input,
figures_dir <- gsub('/$', '', knitr::opts_chunk$get("fig.path"))
files <- list.files(figures_dir, full.names = TRUE, recursive = TRUE)
# https://github.com/rstudio/rmarkdown/issues/1358
if (citeproc) files <- c(files, yaml_front_matter[['bibliography']])
if (citeproc) files <- c(files, front_matter[['bibliography']])
for (f in files) {
intermediates <<- c(intermediates, copy_file_with_dir(f, intermediates_dir))
}
Expand Down Expand Up @@ -908,7 +902,7 @@ render <- function(input,
texfile <- file_with_ext(output_file, "tex")
# determine whether we need to run citeproc (based on whether we have
# references in the input)
run_citeproc <- citeproc_required(yaml_front_matter, input_lines)
run_citeproc <- citeproc_required(front_matter, input_lines)
# if the output format is LaTeX, first convert .md to .tex, and then convert
# .tex to .pdf via latexmk() if PDF output is requested (in rmarkdown <=
# v1.8, we used to call Pandoc to convert .md to .tex and .pdf separately)
Expand Down Expand Up @@ -941,7 +935,7 @@ render <- function(input,

# if there is a post-processor then call it
if (!is.null(output_format$post_processor))
output_file <- output_format$post_processor(yaml_front_matter,
output_file <- output_format$post_processor(front_matter,
utf8_input,
output_file,
clean,
Expand Down

0 comments on commit e4c6234

Please sign in to comment.