Remove blank page for beamer using natbib in Rmarkdown - r

My little example (test.rmd) is as follows:
---
output:
beamer_presentation:
latex_engine: xelatex
citation_package: natbib
bibliography: ref.bib
biblio-style: "unsrtnat"
colorlinks: yes
---
## Papers
- Cp #mallows1973some
- AIC #akaike1974new
- BIC #schwarz1978estimating
- GCV #craven1978smoothing
- bridge #frank1993statistical
- LASSO #tibshirani1996regression
- SCAD #fan2001variable
- MCP #zhang2010nearly
## References {.allowframebreaks}
where ref.bib is
#Article{mallows1973some,
author = {Mallows, Colin L.},
journal = {Technometrics},
title = {{Some comments on $C_p$}},
year = {1973},
number = {1},
pages = {87--94},
volume = {42},
}
#Article{akaike1974new,
author = {Akaike, Hirotugu},
journal = {IEEE Transactions on Automatic Control},
title = {A new look at the statistical model identification},
year = {1974},
number = {6},
pages = {716--723},
volume = {19},
}
#Article{schwarz1978estimating,
author = {Schwarz, Gideon},
journal = {The Annals of Statistics},
title = {Estimating the dimension of a model},
year = {1978},
number = {2},
pages = {461--464},
volume = {6},
publisher = {Institute of Mathematical Statistics},
}
#Article{craven1978smoothing,
author = {Craven, Peter and Wahba, Grace},
journal = {Numerische Mathematik},
title = {Smoothing noisy data with spline functions},
year = {1978},
number = {4},
pages = {377--403},
volume = {31},
}
#Article{frank1993statistical,
author = {Frank, Ildiko E. and Friedman, Jerome H.},
journal = {Technometrics},
title = {A statistical view of some chemometrics regression tools},
year = {1993},
number = {2},
pages = {109--135},
volume = {35},
}
#Article{tibshirani1996regression,
author = {Tibshirani, Robert},
title = {Regression shrinkage and selection via the lasso},
journal = {Journal of the Royal Statistical Society. Series B (Methodological)},
year = {1996},
volume = {58},
number = {1},
pages = {267--288},
publisher = {JSTOR},
}
#Article{fan2001variable,
author = {Fan, Jianqing and Li, Runze},
journal = {Journal of the American Statistical Association},
title = {Variable selection via nonconcave penalized likelihood and its oracle properties},
year = {2001},
number = {456},
pages = {1348--1360},
volume = {96},
}
#Article{zhang2010nearly,
author = {Zhang, Cun-Hui},
journal = {The Annals of Statistics},
title = {Nearly unbiased variable selection under minimax concave penalty},
year = {2010},
number = {2},
pages = {894--942},
volume = {38},
}
My problem is that test.rmd can run successfully while there is a blank page in the second page.
One may suggest that I can use the csl: xxx.csl instead of citation_package: natbib in Rmarkdown for beamer. Surely, csl: xxx.csl is fine and can run without accidents, but I still prefer to using citation_package: natbib.
Curiously, if I change ## References {.allowframebreaks} in test.rmd with
`r if (knitr::is_html_output()) '
## References {.allowframebreaks}
'`
then the blank page disappears. However, a new problem has emerged; the frame title and the bookmark of References both disappear. How can I fix the problems?

Quick hack:
---
output:
beamer_presentation:
latex_engine: xelatex
keep_tex: true
citation_package: natbib
bibliography: ref.bib
biblio-style: "unsrtnat"
colorlinks: yes
header-includes:
- \pretocmd{\bibliographytrue}{\frametitle{References}}{}{}
---
## Papers
- Cp #mallows1973some
- AIC #akaike1974new
- BIC #schwarz1978estimating
- GCV #craven1978smoothing
- bridge #frank1993statistical
- LASSO #tibshirani1996regression
- SCAD #fan2001variable
- MCP #zhang2010nearly

Using # References instead of ## References solves this problem.
---
output:
beamer_presentation:
latex_engine: xelatex
citation_package: natbib
bibliography: ref.bib
biblio-style: "unsrtnat"
colorlinks: yes
---
## Papers
- Cp #mallows1973some
- AIC #akaike1974new
- BIC #schwarz1978estimating
- GCV #craven1978smoothing
- bridge #frank1993statistical
- LASSO #tibshirani1996regression
- SCAD #fan2001variable
- MCP #zhang2010nearly
# References

Related

bibliography or csl directory path in rmarkdown for windows system

My testing files with related directory paths (in windows operating system) are listed as followed
E:\mywork\test.rmd
E:\myref\apa.csl
E:\myref\ref.bib
E:\mydata\xx.csv
In test.rmd, it shows
---
title: "Untitled"
author: "xxx"
date: "xxx"
output: pdf_document
bibliography: "E:/myref/ref.bib" #ok!
# bibliography: "../myref/ref.bib" #ok!
# bibliography: r"(E:\myref\ref.bib)" #no!
# bibliography: "E:\\myref\\ref.bib" #no!
csl: "E:/myref/apa.csl" #https://www.zotero.org/styles
---
# R Markdown
#efron2004least
```{r}
# d0 = write.csv(iris[1:10,],file=r"(E:\mydata\xx.csv)")
d1 = read.csv(r"(E:\mydata\xx.csv)"); head(d1)
d2 = read.csv("E:\\mydata\\xx.csv"); head(d2)
```
# References
and works well, where ref.bib reads
#Article{efron2004least,
author = {Efron, Bradley and Hastie, Trevor and Johnstone, Iain and Tibshirani, Robert},
title = {Least angle regression},
journal = {The Annals of Statistics},
year = {2004},
volume = {32},
number = {2},
pages = {407--499},
}
and apa.csl is downloaded from https://www.zotero.org/styles. In particular, bibliography: "../myref/ref.bib" is also working!
After running ?Quotes in the Console I note that
## A Windows path written as a raw string constant:
r"(c:\Program files\R)"
Thus, I try bibliography: r"(E:\myref\ref.bib)" and bibliography: "E:\\myref\\ref.bib", but these two choices failed. I don't know how to fix them. Or the latter two choices are not permitted in the yaml? (PS: The latter two work for the xx.csv data file case!)

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

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

! Illegal unit of measure (pt inserted) PDF Knit Error

I'm trying to knit a report as a PDF in RStudio. The code I have so far works fine (I've been testing it chunk by chunk) until it gets to the below chunk:
## HCT-CI
```{r}
summaryTable(y=wdata$HCTCI.score, table.title="HCT-CI Raw Score", y.labels="Number of Readmissions")
summaryTable(y=wdata$HCTCI.score, table.title="Readmissions", freq.tab=T, y.name="HCT-CI Raw Score")
summaryTable(y=wdata$HCTCI.3cat, table.title="HCT-CI Score (3 Groups)", caption_heading="Note:", caption="1: Score=0; 2: Score=1-2; 3: Score=3+", freq.tab=T, y.labels=c("0", "1-2", "3+"))
```
\pagebreak
My goal is to generate the output successfully as a PDF.
It's the same functions and format I've used in all the other chunks. When I run the chunk by itself, it also works. I've looked up the issue on google and other stackoverflow posts, but am having a hard time applying their solutions as they all use HTML or a different language.
My full report looks something like this (with some chunks taken out for the sake of brevity):
DOCUMENT BEGINS
---
title:
- \vspace{2in}Analysis for Study$\colon$ Readmissions
subtitle:
- \vspace{.2in}\emph{`r format(Sys.time(), '%d %B, %Y')`}
author:
- \emph{PI$\colon$ Name}
- \emph{College}
- \vspace{.5in}\emph{Author}
- \emph{Position}
- \emph{email}
date:
- \vspace{4in}
header-includes:
- \usepackage{fancyhdr}
- \usepackage{titling}
- \usepackage{caption}
- \fancyhead[L]{\includegraphics[width=2cm]{pic.png}}
- \fancyhead[R]{\includegraphics[width=4cm]{pic.png}}
- \fancyfoot[C]{Department}
- \fancypagestyle{plain}{\pagestyle{fancy}}
geometry: left=.5in,right=.5in,top=1in,bottom=1in
mainfont: Times New Roman
output:
pdf_document:
keep_tex: true
highlight: tango
toc: true
toc_depth: 4
number_sections: true
fig_caption: true
df_print: kable
fontsize: 12pt
---
\captionsetup[table]{labelformat=empty}
```{r setup, include=FALSE}
source("Revised Code.R")
knitr::opts_chunk$set(fig.path='Figs/', fig.align='center', fig.pos="H", echo=FALSE, warning=FALSE, message=FALSE, results = 'asis', fig.width = 6.5, fig.height = 4.5, dev = 'pdf')
\pagebreak
Summary of ___ within 100 days
summaryTable(wdata, table.title="Within 100 Days", y.labels="Number of Readmissions")
summaryTable(wdata, table.title="Within 100 Days", y.labels="Number of Readmissions", freq.tab=T)
summaryTable(wdata, table.title="Within 100 Days", freq.tab=T, y.name="Readmission", y.labels=c("No Readmission", "Any Readmission"))
\pagebreak
Association Between Readmissions and Donor Type
summaryTable(y=wdata$donor, table.title="Donor Type", freq.tab=T, y.name="Donor Type")
summaryTable(y=wdata$donor.3cat, table.title="Association Between Readmissions and Donor Type (3 Groups)", freq.tab=T, y.name="Donor Type", y.labels=c("Matched Sibs", "MUD", "Others"))
regTable.logistic(formula=wdata$readm.any~as.factor(wdata$donor.3cat), response = "Readmission", y.name="Donor Type (3 Groups)", y.labels=c("MUD vs Matched Sibs", "Others vs Matched Sibs"))
summaryTable(y=wdata$readm.any, bygroup=as.numeric(wdata$donor.3cat), freq.tab=T, bygroup.name="Donor Type", y.name="Readmissions", bygroup.labels=c("Matched Sibs", "MUD", "Others"), caption_heading="Note:", caption = "0: No Readmission; 1: Any Readmission")
\pagebreak
Association
HCT-CI
summaryTable(y=wdata, table.title="Raw Score", y.labels="Number of Readmissions")
summaryTable(y=wdata, table.title="Readmissions", freq.tab=T, y.name="Raw Score")
summaryTable(y=wdata, table.title="Score (3 Groups)", caption_heading="Note:", caption="1: Score=0; 2: Score=1-2; 3: Score=3+", freq.tab=T, y.labels=c("0", "1-2", "3+"))
\pagebreak
DOCUMENT ENDS
It's only when I attempt to knit it as a PDF do I get the following error:
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
! Illegal unit of measure (pt inserted).
<to be read again>
)
l.1949 \item
\underline{\textit{Note:}}
Error: Failed to compile Revised_Code.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See Revised_Code.log for more info.
Execution halted
How do I resolve the issue?
The "Illegal unit of measure (pt inserted)." error may also appear when a numerical value is entered for the chunk option out.height. For example out.height=200 generates this error, it should be replaced by out.height="200px".

Resources