LuaLaTex and _output.yml configuration - Error in base format() - r

I am learning how to use bookdown package and right now I am practicing with Yihui Xie minimal example. In my test I want a gitbook and a pdf output.
What I would like to do is to specifying some options for pdf output with LuaLaTeX engine. So if I do something like that :
bookdown::gitbook:
css: style.css
config:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: lualatex
fontsize: 12pt
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
I have this error when I try to build the book :
Error in base_format(toc = toc, number_sections = number_sections, fig_caption = fig_caption, :
unused argument (fontsize = "12pt")
Calls: <Anonymous> ... <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution stoped
Exited with status 1.
If I put fontsize: 12pt in the YAML header of the index.Rmd, I don't have this error. If I use bookdown::pdf_document2: I don't have this error either.
I really don't know what I am missing here... Should I place LaTeX configuration options only in the YAML header of my index.Rmdfile ?

Related

How to solve the "file name conversion problem -- name too long?" error when rendering a publication in Bookdown?

I'm having problems to render a publication in Bookdown. The error message sugests a kind of size problem in some file, but I have no idea how to identify it.
Found these related answers: answer1, answer2, answer3, but none of them solved my problem.
Thanks for any help.
Error in file.exists(f) : file name conversion problem -- name too long? Calls: local ... local_resources -> grep -> is.factor -> unique -> file.exists Interrupted execution Error: bookdown::render_book() failed to render the output format 'bookdown::gitbook'. Interrupted execution Exited with status 1.
This is my _bookdown.yml file configuration:
delete_merged_file: true
new_session: yes
language:
label:
fig: 'Figura '
tab: 'Tabela '
ui:
chapter_name: "Capítulo"
And this is my _output.yml file:
lib_dir: assets
css: style.css
includes:
config:
toc:
before: |
<li>Relatório Geral de Gastos Públicos em 2021"</li>
after: |
<li>Published with bookdown</li>
download: null
sharing:
facebook: no
linkedin: yes
whatsapp: yes
info: no
bookdown::pdf_book:
#pandoc_args: --top-level-division=chapter
keep_text: yes
keep_tex: true
includes:
in_header: preamble.tex
template: template.tex
latex_engine: xelatex
citation_package: natbib
extra_dependencies: ["flafter"]
toc_unnumbered: no
fig_caption: yes
toc_depth: 3
bookdown::epub_book: default

Not finding my bookdown bibliography file

My document is simply this
---
title: "The Visual Speech (VISP) Handbook"
author: "Fredrik Karlsson & Linda Sandström"
site: bookdown::bookdown_site
documentclass: book
output:
bibliography: references.bib
#bookdown::pdf_book: default
bookdown::gitbook: default
biblio-style: "apalike"
link-citations: true
---
# Preface {-}
[#R-base]
and I have a reference file:
> dir(pattern = "*.bib")
[1] "references.bib"
but I am unable to find this bib file when knitting the book:
Error in eval(parse(text = name)) : object 'references.bib' not found
Calls: ... create_output_format ->
create_output_format_function -> eval -> eval Please delete _main.Rmd
after you finish debugging the error. Execution halted
Any ideas on how to set this up properly (in Rstudio)
Thanks!
Fredrik
It's just a location problem in the code (see more information here).
You could try:
---
title: "The Visual Speech (VISP) Handbook"
author: "Fredrik Karlsson & Linda Sandström"
site: bookdown::bookdown_site
documentclass: book
output:
#bookdown::pdf_book: default
bookdown::gitbook: default
bibliography: references.bib
biblio-style: "apalike"
link-citations: true
---
# Preface {-}
[#R-base]

Verbatim code chunks with double quotation marks in RMarkdown

As demonstrated in 4.7 Verbatim code chunks in #Yihui 's R Markdown Cookbook, we can show a verbatim inline expression,
`r knitr::inline_expr("coef(summary(model))")`, for example, in our output of RMarkdown.
However, this knitr::inline_expr() would not be able to parse a code with double quotation marks, such as
`r knitr::inline_expr("coef(summary(model))["(Intercept)", "Estimate"]")`.
Then, what should I do when I want to demonstrate the verbatim which contains such a special characters?
---
title: "Untitled"
author: "CLRR"
date: "2020/6/20"
documentclass: article
output:
bookdown::pdf_document2:
latex_engine: xelatex
keep_tex: TRUE
---
This verbatim can appear in the output:
`` `r knitr::inline_expr("coef(summary(model))")` ``
<!--
But, if the code contains `"`, the evaluation fails.
`r knitr::inline_expr("coef(summary(model))["(Intercept)", "Estimate"]")`
```
Quitting from lines 2-16 (test.Rmd)
Error in parse(text = code, keep.source = FALSE) :
<text>:1:54: unexpected string constant
1: knitr::inline_expr("coef(summary(model))["(Intercept)", "
^
Calls: <Anonymous> ... hook_eval -> withVisible -> eval -> parse_only -> parse
Execution halted
```
-->
You can escape the double quotes:
---
title: "Untitled"
author: "CLRR"
date: "2020/6/20"
documentclass: article
output:
bookdown::pdf_document2:
latex_engine: xelatex
keep_tex: TRUE
---
This verbatim can appear in the output:
`r knitr::inline_expr("coef(summary(model))[\"(Intercept)\", \"Estimate\"]")`
In the comments, #monte provides the other solution, which is alternating single and double quotes: knitr::inline_expr('coef(summary(model))["(Intercept)", "Estimate"]')

R Markdown error

I am trying to create an R markdown file but when I do I get the following error:
Line 2:
Error in .Call(C_str Sub_replacement, str, from, to, NULL, value) :
Incorrect number of arguments (5), expecting 6 for 'C_str Sub Replacement'
Calls: <Anonymous> ... indir -> inline exec -> <Anonymous> -> str_sub<- -> .Call
I have tried searching the internet and can not find an answer to this specific error. I am running R-3.3.0 and using R Studio.
I have updated the packages - knitr, markdown and yaml.
The following is my set up:
---
title: "Setting up a DQASS PC"
author: "DKMillington"
date: "`r format(Sys.Date(), '%d/%m/%Y')`"
header-includes:
- \usepackage{amsmath}
output:
rmarkdown::html_vignette:
css: mystyle.css
toc: true
number_sections: true
---
```{r, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(dqass)
```
Thank you for your time in advance.
Dale

Using a YAML header argument in knitr

I am making a set of slides using rmarkdown and the LaTeX option of outputting it to beamer.
I have two templates I use in my slides - one specific for the LaTeX options, and one pandoc template that I have modified to account for some additional feature of my slides.
I have defined an option in the YAML header called to_print which is a boolean TRUE/FALSE that I pass to the pandoc template that tells it to add a package and clean up the slides for printing.
I also want to use this variable to define the name of the files. The basic idea being that I want to have one .rmd file for my slides, and then just changing this one option to signify that it's for printing by students, or for me presenting.
I have figured out that I can pass the render function using the knit parameter in the YAML header, but I have to specify to_print = TRUE and set the condition in the ifelse() statement in the output_file correspondingly.
Currently I have:
---
title: "Introduction to R"
subtitle: "Reading and saving data in R"
date: '`r format(Sys.Date())`'
output:
beamer_presentation:
fonttheme: professionalfonts
highlight: tango
includes:
in_header: "../../templatefiles/beamer_header.tex"
template: "../../templatefiles/beamer_template.tex"
incremental: no
keep_tex: yes
slide_level: 3
theme: Warsaw
toc: yes
fontsize: 10pt
fontenc: T1
to_print: TRUE
knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding,
output_file = file.path(ifelse(TRUE,
gsub("\\..*","_handout.pdf", inputFile),
gsub("\\..*", ".pdf", inputFile)))) })
---
I would like to specify just one parameter that is then used to signify if this is a handout to be printed:
Pseudo-code:
to_print: TRUE
knit: (function(inputFile, encoding) {rmarkdown::render(inputFile, encoding = encoding,
output_file = file.path(ifelse(YAML_PARAM$to_print,
gsub("\\..*","_handout.pdf", inputFile),
gsub("\\..*", ".pdf", inputFile)))) })
Is this possible, or something equivalent that would let me have one .rmd file with a boolean to toggle presentation vs. printing?
You can use the rmarkdown::yaml_front_matter() function:
---
title: "Introduction to R"
subtitle: "Reading and saving data in R"
date: '`r format(Sys.Date())`'
output:
beamer_presentation:
fonttheme: professionalfonts
highlight: tango
includes:
in_header: "../../templatefiles/beamer_header.tex"
template: "../../templatefiles/beamer_template.tex"
incremental: no
keep_tex: yes
slide_level: 3
theme: Warsaw
toc: yes
fontsize: 10pt
fontenc: T1
to_print: TRUE
knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding,
output_file = file.path(ifelse(rmarkdown::yaml_front_matter(inputFile)$to_print,
gsub("\\..*","_handout.pdf", inputFile),
gsub("\\..*", ".pdf", inputFile)))) })
---

Resources