Output created by pagedown::html_paged not displaying properly - r

I am working on a project in RStudio that takes in multiple rmd files and a yml file and uses the bookdown render_book() function to produce paginated output that can be converted to pdf.
The bookdown code is as follows:
bookdown::render_book("prog1.Rmd", "bookdown::gitbook", config_file = config_yml)
bookdown::render_book("prog1.Rmd", "pagedown::html_paged", config_file = config_yml)
The config_yml file:
book_filename: "Report Output"
delete_merged_file: true
new_session: yes
rmd_files: ["Start.Rmd", "prog1.rmd", "appendix.rmd"]
output_dir: ./fakedir/
language:
label:
fig: "FIGURE "
tab: "TABLE "
before_chapter_script: "./fakename.R"
The specifications from the Start.rmd:
---
title: "Report"
subtitle: "`r text`"
date: "`r datetext`"
site: bookdown::bookdown_site
classoption: oneside
documentclass: book
link-citations: yes
description: "My Report"
---
Historically this has caused no issues, with the first bookdown call creating an html doc and the second creating a paginated version. Recently, with no code changes, the paginated version will not open properly once created. It only shows the title page followed by two blank pages. I have thus far been unable to find a reason for this. I am hoping for either a solution to this issue or an alternative method to producing a paginated document. Let me know if more info/code is needed.

Related

R Bookdown: Append chapter without re-rending whole book

I am rather experienced with R but new to markdown and especially bookdown. I wonder how to render a single chapter and merge it with the existing book without re-building the whole book. The reason why I am asking is that I am creating a book that contains parameterised chapters and each chapter runs very long (1-2 hours). All in all, it will be hundreds of chapters with the same analysis, but different input data and would time-wise add up. I am aware of the knit-and-merge approach, in fact, that's the reason why I chose bookdown, but somehow it is not working as expected.
I am honestly also a little bit confused by the different rendering possibilities. There is the built-book button, the knit button, serve_book(), render_book(), preview_chapter(), ... I figured that one should avoid using the knit button in bookdown and that serve_book() will automatically compile changes. My approach so far is entering serve_book() into console, where it renders the whole book, then I create a new chapter, hit save and it runs the chunks of only that chapter (exactly what I want!) and the single HTML file of the new chapter appears. However, it doesn't show them when I look at the book via the index.html file.
I am only interested in an HTML book and do not need any other output formats.
In order to recreate the problem, I am just using the bookdown example and adding chapters to it.
_bookdown.yaml
book_filename: "book_name"
new_session: yes #true
before_chapter_script: _common.R
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
_output.html
bookdown::bs4_book:
css: style.css
theme:
primary: "#10395B"
#repo: https://github.com/rstudio/bookdown-demo
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
_index.yaml
---
title: |
![](./Logo_PureGene.png){width=200px}|
|-|
||
author: "Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
#output: bookdown::bs4_book
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::bs4_book,
set in the _output.yml file.
biblio-style: apalike
csl: chicago-fullnote-bibliography.csl
---
# About {-}
I would appreciate any help!
Thanks in advance :)

Why Rmarkdown Dynamic TITLE in YAML does not appear in the pdf file

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?
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

Include an extra section of text/hyperlink in YAML-Header section of Rmarkdown document

I'm writing a document in RMarkdown and have hopefully a fairly straightforward query about including extra information in the header section.
My Header section of the rmd looks like:
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)"
output: html_document
---
I'm trying to add a simple extra line after my name which includes my Twitter handle
I tried cheating by adding it as an abstract....:
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)"
abstract: "[I'm on Twitter](hyperlink)"
output: html_document
---
But that displays the heading Abstract before the extra information i.e I get
"Abstract: I'm on Twitter"
Whereas the desired output would be
Title Text
Name (Hyperlink)
I'm on Twitter (Hyperlink)
Anyone know how to get this to work?
I've looked at PANDOC Guide and other examples and I've tried all sorts of things calling it description, institute but none of these seem to render except for Abstract which has the issue highlighted above.
NB: Modified-extra query
This works for an HTML output but doesn't seem to if output == PDF
Any suggestions in that realm also welcomed!
There are a couple of ways to render the RMarkdown YAML header content for a single field on multiple lines. The following examples work for me in both pdf and html formats:
Using two spaces followed by \n
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page) \n[I'm on Twitter](hyperlink)"
output:
pdf_document: default
html_document: default
---
Using the | operator
---
title: "My R-Markdown Document"
author: |
| [My name here](a hyperlink to my institutional page)
| [I'm on Twitter](hyperlink)
output:
pdf_document: default
html_document: default
---
Using html line break <br> (works for html, not pdf)
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)<br><br>[I'm on Twitter](hyperlink)"
output: html_document
---
Note, including additional information like this in the author field may not be ideal as the additional information will also be included in the rendered html author metadata:
<meta name="author" content="My name here I’m on Twitter" />
These questions might also be helpful:
In YAML, how do I break a string over multiple lines?
Split the title onto multiple lines?

R markdown / bookdown - how to switch to rticles?

Input data
I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF.
I placed it on dropbox:
https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0
Question
Now I wish to set as an output format 'rticles::elsevier_article'
How can I do that?
Issue
When I change output line from:
bookdown::pdf_document2
to
rticles::elsevier_article
I'm receiving an error message.
Even if I remove other parameters from output:
I still receive an error message:
! Undefined control sequence.
Accented characters when input "as is" do not appear to behave well with elsevier_article. See suggestions below.
Bare-bones document
Here is a bare-bones document using rticles::elsevier_article:
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
Hello world.
which renders with no complaints:
Reference with accents
Now, we wish to add a reference with accents. We follow the answer here: https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography. I imported your bibliography into Zotero, and then exported the item with a "Central European (ISO)" encoding (not UTF-8) to obtain
#article{kedzior_this_2018,
title = {This is sample title only {\k A} {\L }},
volume = {99},
url = {http://megooglethat.com/},
journal = {Some journal},
author = {K{\k e}dzior, Mateusz and {\'Z}{\k e}{\'n}, {\.Z}{\k a}{\'c}{\l }},
year = {2018},
keywords = {keywordC},
pages = {21 -- 31}
}
The R Markdown document now becomes
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
biblio-files: bibliography2.bib
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
## Citations and references
Let me cite an article: [#kedzior_this_2018]
# References
I then knited this in RStudio, but realised that I had to get the tex output and rebuild it (outside of RStudio) to get the desired output
Other problems
For accented characters in figure captions, encode them accordingly (as with the bibliography). You may find http://w2.syronex.com/jmr/latex-symbols-converter helpful. In addition, to the best of my knowledge bookdown style cross-referencing does not work with rticles. If you have follow-up questions, you may get more helpful answers if you break your question down into smaller chunks.
I've added a bit of updated material to the commenthttps://github.com/rstudio/rticles/issues/92#issuecomment-402784283 where it states (may be updated):
output:
bookdown::pdf_document2:
base_format: rticles::elsevier_article
number_sections: yes
such that the way I've had this work is using pdf_book versus pdf_document2:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
number_sections: yes
This allows for figure and table referencing within an rticles document.

knitr/pandoc: article template supporting keywords: and linespacing:

I'm using the latest R Studio, R 3.2.5, rmarkdown 0.9.6, which comes with pandoc 1.15.2 to write a journal article. Submission requires: linespacing: 1.43 and a keywords: line just below the abstract.
When I click Knit PDF I get the default template "C:\R\R-3.2.5\library\rmarkdown\rmd\latex\default-1.15.2.tex" which does not support these fields in the YAML header. I see that default-1.17.02.tex supports linespacing:, but not keywords:.
I tried to modify the latter template to add keywords handling, which seemed pretty straight-forward. The relevant portion of the template, that I called modified-template-1.17.0.2.tex is
$if(title)$
\maketitle
$endif$
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$
\providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
$if(keywords)$
\keywords{$keywords$}
$endif$
I used the YAML header below, and pandoc found it; however, it generated .tex syntax errors, unrelated to the keywords: field. I'm thinking that the rmarkdown templates are specific to the version of pandoc, but I have no way to tell.
can anyone help with this?
---
title: "My title"
author: ME
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
template: "modified-template-1.17.0.2.tex"
keywords: Box M test, HE plots, MANOVA, graphics, ...
abstract: "This paper explores a variety of fascinating topics ... "
---
Note added: I tried this modifying the default-1.15.2.tex template as described above. My result is the same, and the error I get is:
! Undefined control sequence.
l.527 {\centering \includegraphics
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
One more test: I simply used a copy of the standard default-1.15.2.tex template in my local folder, with the YAML line
template: "default-1.15.2.tex"
This also gives the same error, so I am mystified as to the cause.
This is an answer to the keywords: problem. It is admittedly a kludge, but doesn't require changing the template: Simply include the keywords as an additional paragraph in the abstract in the YAML header.
abstract: "This paper explores a variety of topics ...
**Keywords**: Box's M test; HE plots; MANOVA; graphics
"
To format as a separate paragraph required two blank lines
For posterity, one solution that seems to work is to copy default-1.17.02.tex to the working directory and modify it to include the keywords argument. In the renamed modified-1.17.02.tex, add this after the if block for the author name:
$if(keywords)$
pdfkeywords={$for(keywords)$$keywords$$sep$; $endfor$},
$endif$
And then later in the document, after the if block for placing the abstract:
\providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
$if(keywords)$
\keywords{$keywords$}
$endif$
In the project Rmd file, we just need to specify that we are using our custom template, specify that graphics = true (to circumnavigate the \includegraphics error) and the keywords themselves:
---
title: "My title"
author: ME
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
pdf_document:
template: modified-template-1.17.0.2.tex
graphics: yes
keywords: keyword 1; keyword 2; et cetera
abstract: "Abstract here."
---
Body of article here.
Compiling yields a title page with the keywords field present:
EDIT: The OP also mentioned line spacing. When using the 1.17.02.tex style (used automatically if the most recent version of Pandoc is available, either through manual install or by using the latest RStudio preview build), the ability to adjust the line spacing is done by setting linestretch: 1 for single space, and linestretch: 2 for double anywhere in the YAML header.

Resources