Increase header levels of child documents - r

I want to create a single PDF document from many .Rmd child documents using pdf_document2().
I have a wrapper file pdf_wrapper.Rmd that looks as follows
---
title: "title"
author: "author"
output:
bookdown::pdf_document2:
number_sections: true
---
# Header1
```{r child = 'child1.Rmd'}
```
With child1.Rmd having the following content
---
title: "Title2"
output: rmarkdown::html_document
---
## Title 3
Now when I render pdf_wrapper.Rmd, I get the following:
# Header 1
## Title 3
I want to end up with
# Header 1
## Title 2
### Title 3

I put all level 2 headers manually in the main document pdf_wrapper.Rmd, e.g. Title2.
Additionally, I decreased all remaining headers in all child documents by one level using the following bash call:
for i in *.Rmd; do
sed -i '# /## /g' $i
done
The main document then looks as follows:
---
title: "title"
author: "author"
output:
bookdown::pdf_document2:
number_sections: true
---
# Header1
## Title2
```{r child = 'child1.Rmd'}
```
Initially I though that the <title> fields in the YAML metadata of the child documents get processed as level 1 headers but this is not the case.

Related

How to insert two separate bibliographies (without citing them in the body text) under two separate headers in R Markdown?

Consider the following R Markdown code:
---
title: 'John Doe'
output: pdf_document
bibliography: [bib1.bib, bib2.bib]
nocite: '#*'
csl: vancouver.csl
---
# Peer-reviewed publications
# Other publications
bib1.bib code:
#article{article1,
Author = {Doe, John},
Title = {{Article 1 name}},
Journal = {{Journal 1 name}},
Year = {{2021}},
Volume = {{1}},
Pages = {{1-2}},
}
#article{article2,
Author = {Doe, John},
Title = {{Article 2 name}},
Journal = {{Journal 2 name}},
Year = {{2020}},
Volume = {{1}},
Pages = {{1-2}},
}
bib2.bib code:
#article{article3,
Author = {Doe, John},
Title = {{Article 3 name}},
Journal = {{Journal 3 name}},
Year = {{2021}},
Volume = {{1}},
Pages = {{1-2}},
}
The knit output:
However, I'm rather looking after the following output:
Please note that I don't want in-text citations but rather the whole bibliographies listed, which is why I approached the problem by adding the "nocite: '#*'" to the code, but I couldn't get the result I'm after.
By the way, I used the csl style vancouver.csl (please see: https://www.zotero.org/styles?q=vancouver) here.
Any help is greatly appreciated.
You could use biblatex to split the bibliographies:
---
title: 'John Doe'
output:
pdf_document:
keep_tex: true
csl: vancouver.csl
header-includes:
- \include{preamble.tex}
---
with preamble.tex:
\usepackage[style=vancouver]{biblatex}
\addbibresource{bib1.bib}
\addbibresource{bib2.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\perdatasource{bib1.bib}
\step[fieldset=keywords, fieldvalue={,peer}, append]
}
}
}
\AtEndDocument{\nocite{*}
\printbibliography[keyword={peer},title={Peer-reviewed publications}]
\DeclareFieldFormat{labelnumber}{%
\ifinteger{#1}
{\number\numexpr#1-2\relax}
{#1}}
\printbibliography[notkeyword={peer},title={Other publications}]}
And then compile the resulting filename.tex file with
pdflatex filename
biber filename
pdflatex filename

Passing multiple parameters in RMarkdown document

I am looking to pass multiple parameters in my RMarkdown document. I have the following as an example:
mvndr_nm <- c('name1', 'name2', 'name3', 'name4', 'name5', 'name6')
I also have
mvndr_nbr<- c('60031167', '60688509', '60074051', '60148060', '60086898', '60080204')
I created a unique Markdown document using params and a loop that prints each out doing the following:
for (i in c('60031167', '60688509', '60074051', '60148060', '60086898', '60080204')) {
rmarkdown::render("C:/Users/santi/Documents/R Scripts/Export_Data_CSV.Rmd",
output_file = sprintf("MVNDR_%s.html", i),
params = list(MVNDR_NBR = i))
}
My print out look as such, I would like the first circle to actually be the names, instead of numbers. I tired to do that in the comment below, however it did not show the name despite calling the params function. Below the image is my logic :
---
title: "`r params$MVNDR_NBR`"
author: "Santiago Canon"
date: "5/26/2021"
output:
html_document:
highlight: monochrome
theme: flatly
params:
MVNDR_NBR: sample_vendor_tbl$MVNDR_NBR
MVNDR_NM: vendor_nm$MVNDR_NM
---
<font size="4"> This document will provide a summary of "`r params$MVNDR_NM`" performance within in QC: </font>
To be clear what I simply want is to pass the names through the title and some comments I will make it in the document. It works perfectly fine with the numbers but not the names
RMD file -
---
title: "`r params$MVNDR_NBR`"
author: "Santiago Canon"
date: "5/26/2021"
output:
html_document:
highlight: monochrome
theme: flatly
params:
MVNDR_NBR: NA
MVNDR_NM: NA
---
<font size="4"> This document will provide a summary of "`r params$MVNDR_NM`" performance within in QC: </font>
for loop -
mvndr_nm <- c('name1', 'name2', 'name3', 'name4', 'name5', 'name6')
mvndr_nbr<- c('60031167', '60688509', '60074051', '60148060', '60086898', '60080204')
for (i in seq_along(mvndr_nm)) {
rmarkdown::render("C:/Users/santi/Documents/R Scripts/Export_Data_CSV.Rmd",
output_file = sprintf("MVNDR_%s.html", mvndr_nbr[i]),
params = list(MVNDR_NBR = mvndr_nbr[i], MVNDR_NM = mvndr_nm[i]))
}
Output -
MVNDR_60031167.html
MVNDR_60688509.html -

Tables appears in disorder in appendix section (R-markdown)

I'm writing my Ms thesis with R markdown, and I have a problem with the Appendix section. I need to put some tables in the appendix section but when I render it the header of the subsection appears below de table. like this:
I would like to know if there are some way to fix this.
The way I write the code is:
# Appendix {-}
## Subsection title
chunk with table
R-markdown chunk:
title: "Title of my thesis"
subtitle:
author:
- "Student :"
- "Director: "
output:
pdf_document:
number_sections: true
latex_engine: xelatex
template: NULL
word_document: default
degree: Ms Biology
field: Experimental biology
year: 2021
geometry: left=2cm,right= 2 cm,top=2 cm, bottom=2 cm
papersize: a4
header-includes:
- \usepackage{amsmath}
- \usepackage{booktabs}
- \usepackage{pdflscape}
- \usepackage[justification=raggedright,labelfont=bf,singlelinecheck=false]{caption}
- \usepackage{setspace}
bibliography: library.bib
csl: apa7.csl
fontsize: 11 pt
indent: true
spacing: 1.5
And chunk options
knitr::opts_chunk$set(
echo = FALSE,
warning = FALSE,
message = FALSE,
error =FALSE)
Well, in order to stop putting tables under de subtitle, I have to add
- \usepackage{flafter}
Then the table appears in the next page, in order to avoid that, I added
kbl(data)%>%
kable_styling(latex_options = "hold_position")
That's all.

How to use pass variables in rmarkdown pdf?

I'm trying to pass variables to rmarkdown report as params but i'm not able to render it in the report
the below one is my code the my_value param is dataframe having only single row
---
title
output:
pdf_document: default
output:
pdf_document:
keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
params:
my_class:"smile"
my_value: data$percent
--
`r params$my_value` is the total percentage of customers
`r params$my_class` is product which has been doing better
The YAML header you're using isn't valid.
title tag should finish by : and have a value : title: "test"
output should only be used once
finish header with ---
Try:
---
title: "test"
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
classoption: svgnames
params:
my_class: "smile"
my_value: NA
---
Regarding parameters, you can't directly use data$percent as parameter value in YAML header.
Knitting is done in a new environment, data$percent doesn't exist in it.
In YAML, you could use following settings:
params:
my_class:"smile"
my_value: NA
In calling script:
# data definition
data <- ...
params <- list(
my_class = "more smiles",
my_value = data$percent
)
rmarkdown::render("MyDocument.Rmd", params = params)
For more information : https://bookdown.org/yihui/rmarkdown/params-knit.html

How to fix errors in building a book in r bookdown

building my book in R bookdown using the build tab but running into errors
I have updated my R and R Studio to the latest version
---
title: "Lessons for Africa"
subtitle:
- "By"
- "Saanuo"
author:
- "A thesis submitted to"
- "MASTER’S OF PHILOSOPHY"
- "[FINANCE]"
date: "June, 2020"
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
citation_package: none
toc: true
fig_width: 8
fig_height: 6
fig_caption: true
mainfont: Timesnewroman
fontsize: 12pt
linestretch: 1.5
toc-depth: 3
lot: True
lof: True
site: bookdown::bookdown_site
documentclass: book
bibliography: library.bib
csl: harvard-educational-review.csl
link-citations: yes
geometry: "left=4cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
---
\pagenumbering{roman}
# ->Declaration<- {-}
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.
===
# ->Dedication<- {-}
You can also embed plots, for example:
===
# ->Acknowledgement<- {-}
You can also embed plots, for example:
===
# ->Abstract<- {-}
You can also embed plots, for example:
===
# ->Abbreviations<- {-}
library(tidyverse)
library(knitr)
data_frame(
Abbreviation = c("WM", "STM", "LTM"),
Term = c("Working memory", "Short-term memory", "Long-term memory")) %>%
arrange(Abbreviation) %>%
kable(booktab = T)
I wanted to build my book by encountering this error message. Xie please this the my entire index file, as requested. Thank you for your concern. Much appreciated. Hope this helps give my clarity to my problem.
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: mapping values are not allowed in this context at line 19, column 14
Calls: <Anonymous> ... enumerate_output_formats -> yaml_load_file -> yaml_load -> <Anonymous>
Execution halted
Exited with status 1.

Resources