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 https://github.com/inbo/INBOmd/blob/post_processor/R/rsos_article.R https://github.com/inbo/INBOmd/blob/post_processor/inst/rmarkdown/templates/rsos_article/skeleton/skeleton.Rmd is an Rmd is a MWE that fails compile because the post_processor() is not run. Best regards, Thierry 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)], "\\begin{fmtext}", text[(maketitle + 1):(end_first_page - 1)], "\\end{fmtext}", "\\maketitle", text[(end_first_page + 1):length(text)] ) writeLines(enc2utf8(text), output_file, useBytes = TRUE) } output_file } output_format( 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 Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium 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]]
Are you sure that you want to read in the output_file in text <- readLines(output_file, warn = FALSE)? best regards, Heinz Thierry Onkelinx wrote/hat geschrieben on/am 06.09.2017 11:41:> 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 > https://github.com/inbo/INBOmd/blob/post_processor/R/rsos_article.R > https://github.com/inbo/INBOmd/blob/post_processor/inst/rmarkdown/templates/rsos_article/skeleton/skeleton.Rmd > is an Rmd is a MWE that fails compile because the post_processor() is not > run. > > Best regards, > > Thierry > > 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)], > "\\begin{fmtext}", > text[(maketitle + 1):(end_first_page - 1)], > "\\end{fmtext}", > "\\maketitle", > text[(end_first_page + 1):length(text)] > ) > writeLines(enc2utf8(text), output_file, useBytes = TRUE) > } > output_file > } > > output_format( > 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 > Forest > team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance > Kliniekstraat 25 > 1070 Anderlecht > Belgium > > 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]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Heinz T?chler +436605653878
Dear Heinz, Yes. The idea of the post_processor() is that 1) pandoc converts the .md to .tex 2) the post_processors changes the .tex 3) the .tex is compiled into .pdf Hence the post_processors need to read, change and overwrite the tex output file. Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium 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 2017-09-07 9:08 GMT+02:00 Heinz Tuechler <tuechler at gmx.at>:> Are you sure that you want to read in the output_file in > > text <- readLines(output_file, warn = FALSE)? > > best regards, > > Heinz > > > Thierry Onkelinx wrote/hat geschrieben on/am 06.09.2017 11:41: > >> 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 >> https://github.com/inbo/INBOmd/blob/post_processor/R/rsos_article.R >> https://github.com/inbo/INBOmd/blob/post_processor/inst/ >> rmarkdown/templates/rsos_article/skeleton/skeleton.Rmd >> is an Rmd is a MWE that fails compile because the post_processor() is not >> run. >> >> Best regards, >> >> Thierry >> >> 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)], >> "\\begin{fmtext}", >> text[(maketitle + 1):(end_first_page - 1)], >> "\\end{fmtext}", >> "\\maketitle", >> text[(end_first_page + 1):length(text)] >> ) >> writeLines(enc2utf8(text), output_file, useBytes = TRUE) >> } >> output_file >> } >> >> output_format( >> 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 >> Forest >> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance >> Kliniekstraat 25 >> 1070 Anderlecht >> Belgium >> >> 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]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > -- > Heinz T?chler +436605653878 > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
On 06/09/2017 5:41 AM, Thierry Onkelinx wrote:> 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 > https://github.com/inbo/INBOmd/blob/post_processor/R/rsos_article.R > https://github.com/inbo/INBOmd/blob/post_processor/inst/rmarkdown/templates/rsos_article/skeleton/skeleton.Rmd > is an Rmd is a MWE that fails compile because the post_processor() is not > run. >I installed it and tried running it using debug(INBOmd::rsos_article) rmarkdown::render("skeleton.Rmd") then after post_processor was defined, I set it to debug as well, and could see that the post_processor was being run. I didn't get useful output, because the LaTeXing failed (I don't have the rsos.cls), but perhaps you've already fixed this problem, or perhaps it is intermittent? Duncan Murdoch> Best regards, > > Thierry > > 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)], > "\\begin{fmtext}", > text[(maketitle + 1):(end_first_page - 1)], > "\\end{fmtext}", > "\\maketitle", > text[(end_first_page + 1):length(text)] > ) > writeLines(enc2utf8(text), output_file, useBytes = TRUE) > } > output_file > } > > output_format( > 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 > Forest > team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance > Kliniekstraat 25 > 1070 Anderlecht > Belgium > > 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]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Dear Duncan, Thanks for chiming in. Could you explain how you set debug() on post_processor()? I've tried adding debug(post_processor) to rsos_article() or adding debug(post_processor) when after post_processor was defined in the debugger. Neither work for me. All supporting files are available within the package. The code below should be reproducible on your machine. remove.packages("INBOmd") devtools::install_github("inbo/INBOmd at post_processor") setwd(system.file("rmarkdown/templates/rsos_article/skeleton", package "INBOmd")) debug(INBOmd::rsos_article) rmarkdown::render("skeleton.Rmd") The sign that post_processor() fails when the tex file still contains \EndFirstPage resulting in the compilation error "Undefined control sequence. l.128 \EndFirstPage" I still get the error with the current version of the code. Running the post_processor manually works. eval(parse( text = readLines( " https://raw.githubusercontent.com/inbo/INBOmd/post_processor/R/rsos_article.R " )[72:92] )) post_processor(output_file = "skeleton.tex") system("pdflatex skeleton.tex") Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium 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 2017-09-07 12:14 GMT+02:00 Duncan Murdoch <murdoch.duncan at gmail.com>:> On 06/09/2017 5:41 AM, Thierry Onkelinx wrote: > >> 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 >> https://github.com/inbo/INBOmd/blob/post_processor/R/rsos_article.R >> https://github.com/inbo/INBOmd/blob/post_processor/inst/ >> rmarkdown/templates/rsos_article/skeleton/skeleton.Rmd >> is an Rmd is a MWE that fails compile because the post_processor() is not >> run. >> >> > I installed it and tried running it using > > debug(INBOmd::rsos_article) > rmarkdown::render("skeleton.Rmd") > > then after post_processor was defined, I set it to debug as well, and > could see that the post_processor was being run. > > I didn't get useful output, because the LaTeXing failed (I don't have the > rsos.cls), but perhaps you've already fixed this problem, or perhaps it is > intermittent? > > Duncan Murdoch > > Best regards, >> >> Thierry >> >> 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)], >> "\\begin{fmtext}", >> text[(maketitle + 1):(end_first_page - 1)], >> "\\end{fmtext}", >> "\\maketitle", >> text[(end_first_page + 1):length(text)] >> ) >> writeLines(enc2utf8(text), output_file, useBytes = TRUE) >> } >> output_file >> } >> >> output_format( >> 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 >> Forest >> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance >> Kliniekstraat 25 >> 1070 Anderlecht >> Belgium >> >> 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]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> >[[alternative HTML version deleted]]