0

I am trying to generate dynamic PDF reports from Rmarkdown with dynamic titles. To do this I use the function rmarkdown::render() in my R script and I pass in the argument params the title parametre as set.title = title.

The YAML of my Rmarkdown script I have the next code:

author: "Author test"
date: "`r Sys.setlocale('LC_TIME','C');format(Sys.Date(),'%B %d, %Y')`"
output:
  pdf_document:
    toc: yes
    toc_depth: 5
    keep_tex: yes
  html_document:
    theme: united
    toc: yes
classoption: table
header-includes:
  - \usepackage{array}
  - \usepackage{float}
  - \usepackage{xcolor}
  - \usepackage{caption}
  - \usepackage{longtable}
  #- \usepackage{mulicol}
params: 
  set.title: title
title: "`r params$set.title`"

Once I run my code everything goes well and generate the different pdfs that I expect, the problem is that neither of these PDFs show the title, author and date. I am working with version 1.8 of rmarkdown package.

Can anyone help me with this issue?

  • 1
    I suggest you upgrade `rmarkdown` and try again. I'm currently on 1.10 (1.11 is on CRAN) and this example worked as-is showing title, author, and date. (I'm using win10 and R-3.5.1 if it matters.) – r2evans Jan 19 '19 at 19:45
  • 1
    I have updated the rmarkdown package to the 1.11 version, but even doing this my pdf files are not showing **title**, **author** and **date**. The thing is that in the console the title of each document appears while running, but later on the pdf generation appears nothing. – Laura Santulario Verdú Jan 19 '19 at 23:11
  • @LauraSantularioVerdú BTW, you need to remove the indent on the line in which `header-includes:` appears. The indent prevented me producing the output and I got the right result when I omitted it. – Carlos Luis Rivera Jan 20 '19 at 03:40
  • I'm not sure why you don't write down your document title directly in the `title` section, e.g. `title: "This is the title"`, rather than `params: set.title: This is the title`. Could you tell me the motivation or the benefit to do so? – Carlos Luis Rivera Jan 20 '19 at 04:01
  • 1
    Carlos: I do something similar, changing the title for parameterized reports. It's legit, though I still cannot reproduce the problem. – r2evans Jan 20 '19 at 05:31
  • Laura, I copied this verbatim with a few changes: fix the indent before `header-includes:`, fix the ridiculous multi-backticks with single backticks (SO format problem?), encapsulate this block with `---` before and after, then add *some* text (as a document body), and it compiles without error and shows title, author, date, and document body. Something on your system is wrong, whether it's something you did or something else. Please include the output from `sessionInfo()` or `devtools::session_info()` (either, not both). – r2evans Jan 20 '19 at 05:34
  • 1
    @r2evans someone has change the code of my question. I did not have indent before `header-includes:`, I had only one backticks in the place they should be and all was encapsulate with `---`. Even this with a text in the document body I do not get any **title**, **author** and **date**. @Carlos Ruiz Rivera I do not write directly the title because I want to get more than one report running only one time my code and all these reports have different titles. – Laura Santulario Verdú Jan 20 '19 at 18:36
  • I understand (somebody else editing it). I also worked off of your original/unmodified question and the current version, and they both worked without problem. Ergo I think it's something to do with (a) your R or package versions, or (b) your LaTeX availability. I'm sorry I cannot provide any assistance, but it does not fail for me. Take a look at your installation of LaTeX, be it texlive, tinytex, miktex, or something else. (I'm currently using [TinyTeX](https://yihui.name/tinytex/), so perhaps the problem is there.) – r2evans Jan 20 '19 at 19:39
  • 1
    @r2evans thank you for your help. Me I am using Miktex so it could be this. I will try to use TinyTex and see if the problem can be solved. – Laura Santulario Verdú Jan 20 '19 at 19:53
  • 1
    @r2evans thank you for help. I found out why the title did not appear in my pdf document and the reason was not related with YAML. The reason was that in reality I was using a the function **cat()** in the varible __title__ that I pass as a parametre and this function changes the value of variable __title__ into NULL. Sorry for my mistake and thanks a lot for your help. – Laura Santulario Verdú Jan 22 '19 at 10:56
  • Yes, that would do it, `cat` is only useful for putting something in the console (and a little crudely at that). It might be nice if it invisibly returned is string, but that is not the case (nor likely to happen). Good sleuthing, glad you found it! – r2evans Jan 22 '19 at 14:22

1 Answers1

0

For closing the conversation of this question I write how has been solved this question. At the beginning I was thinking this issue was related with the code in YAML (where the title was informed from parameters) but eventually I discovered that there was nothing to do that. The problem was that I was using a the function cat() in the varible title that I pass as a parametre and this function changes the value of variable title into NULL.

For knowing exactly all the explanation about how to write dynamic titles in rmarkdown documents redirect yourself to the next entrance: Setting document title in Rmarkdown from parameters