[R] post_processor in rmarkdown not working

Thierry Onkelinx thierry.onkelinx at inbo.be
Wed Sep 6 11:41:46 CEST 2017

Dear all,

I'm trying to write a post_processor() for a custom rmarkdown format. The
goal of the post_processor() is to modify the latex file before it is
compiled. For some reason the post_processor() is not run. The
post_processor() does work when I run it manually on the tex file.

Any suggestions on what I'm doing wrong? Below is the relevant snippet of
the code. The full code is available at
is an Rmd is a MWE that fails compile because the post_processor() is not

Best regards,


  post_processor <- function(
    metadata, input_file, output_file, clean, verbose
  ) {
    text <- readLines(output_file, warn = FALSE)

    # set correct text in fmtext environment
    end_first_page <- grep("\\\\EndFirstPage", text) #nolint
    if (length(end_first_page) == 1) {
      maketitle <- grep("\\\\maketitle", text) #nolint
      text <- c(
        text[1:(maketitle - 1)],
        text[(maketitle + 1):(end_first_page - 1)],
        text[(end_first_page + 1):length(text)]
      writeLines(enc2utf8(text), output_file, useBytes = TRUE)

    knitr = knitr_options(
      opts_knit = list(
        width = 60,
        concordance = TRUE
      opts_chunk = opts_chunk,
      knit_hooks = knit_hooks
    pandoc = pandoc_options(
      to = "latex",
      latex_engine = "xelatex",
      args = args,
      keep_tex = keep_tex
    post_processor = post_processor,
    clean_supporting = !keep_tex

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

	[[alternative HTML version deleted]]

More information about the R-help mailing list