Error in YAML when knitting RMarkdown document - Scanner error - r

I'm trying to knit an RMD file in RStudio but I get the following error
Error in yaml::yaml.load(string, ...) : Scanner error: while scanning a plain scalar at line 31, column 5 found a tab character
that violate intendation at line 34, column 1 Calls: ...
parse_yaml_front_matter -> yaml_load_utf8 -> Execution
halted
The header of the rmd file is as following:
> ---
> title: "Homework 4"
> author: NAME OF THE AUTHOR, Fall 2018
> date: Due Friday, September 30, 11:59pm
> subparagraph: yes
> output:
> pdf_document:
> number_sections: true header-includes:
> - \setcounter{secnumdepth}{1}
> - \pagenumbering{gobble}
> - \sloppy
> - \hypersetup{ breaklinks=true,
> pdftitle={\#title},
> pdfauthor={\#author},
> colorlinks=true,
> breaklinks=true,
> urlcolor= blue,
> linkcolor= blue,
> citecolor=blue,
> bookmarksopen=false,
> pdftoolbar=false,
> pdfmenubar=false
> }
> - \usepackage{titlesec}
> - \renewcommand{\thesection}{\arabic{section}.}
> - \usepackage{mathpazo}
> - \usepackage{etoolbox}
> - \usepackage{geometry}
> - \usepackage{graphicx}
> - \newcommand{\protectbracket}[1]{#1}
> - \makeatletter
> \protectbracket{\preto\Gin#extensions{svg,}}
> \DeclareGraphicsRule{.svg}{pdf}{.pdf}{\noexpand\Gin#base.pdf} \makeatother
> - \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
> - \usepackage[most]{tcolorbox}
> - \definecolor{block-gray}{gray}{0.85}
> - \newtcolorbox{darkquote}{colback=block-gray,grow to right by=-10mm,grow to left by=-10mm, boxrule=0pt,boxsep=0pt,breakable}
> - \renewenvironment{quote}{\begin{darkquote}}{\end{darkquote}\ignorespacesafterend}
> ---
Any ideas what is causing this? The error is pointing to character "n" in line 31 which I am not sure how to fix it. any help or suggestion is highly appreciated.
I have tried this with both RStudio installed on both mac and PC.

Assuming those > at the beginning of the line are left-overs from copy and paste (they for sure should not be in the file), you have a YAML document that starts like:
---
title: "Homework 4"
author: NAME OF THE AUTHOR, Fall 2018
date: Due Friday, September 30, 11:59pm
subparagraph: yes
output:
pdf_document:
number_sections: true header-includes:
- \setcounter{secnumdepth}{1}
and that is invalid as you you cannot have both a mapping as value for the key pdf_document as well as a sequence (less indented in addition).
That, probably combined with the combination of the inline colon-space and end-of-line-colon on one line, confuses that parser
You probably want to change that to something beginning with:
---
title: "Homework 4"
author: NAME OF THE AUTHOR, Fall 2018
date: Due Friday, September 30, 11:59pm
subparagraph: yes
output:
pdf_document:
number_sections: true
header-includes:
- \setcounter{secnumdepth}{1}

Related

Isoslides presentation, incremental bullet points for subsections

In an isoslides_presentation, creating incremental (in terms of time: one after another) bullet points can be done by following code:
> - point 1
> - point 2
But how do I achieve this for lower hierarchy points?
Something like this (both not working):
> - point 1
> - subpoint 1.1
> - subpoint 1.2
> - point 2
> - subpoint 2.1
> - subpoint 2.2
or this
> - point 1
> - subpoint 1.1
> - subpoint 1.2
> - point 2
> - subpoint 2.1
> - subpoint 2.2
I found a reference (https://rpubs.com/eli_3357/ioslides), that states:
A section can also be incremental
using > * for the first line, and >tab* for the following lines"
But I can not get it to run.
In reply to the comment, here is a more complete RepEx:
---
title: "Test"
subtitle: "I do tests"
output:
ioslides_presentation:
smaller: yes
slidy_presentation: default
---
# Slide 1
> - Point 1: to show after first click
> - point 1.1: to show after second click
> - point 1.2: to show after third click
> - Point 2: to show after fourth click
> - and so on ...
#######################################
# Slide 2 {.build}
> - I'm, aware of the build-option...
> - ...but this also gives not the intended result ...
> - ... and all sub-bullets appear at once
This worked for me.
---
title: "Untitled"
date: "18/10/2022"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Slide with Bullets
- Bullet 1
- Sub-bullet 1
- Sub-bullet 2
- Bullet 2
- Bullet 3

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

Incosistency between RMardkown preview and pdf output

I have this latex code in an RMarkdown file in R studio:
---
title: "matrix"
date: "November 2, 2016"
output:
pdf_document: default
---
$$
\mathbf{y} = \left[\begin{array}
{rrr}
y_{1,1} \\
y_{4,3}
\end{array}\right]
\mathbf{X} = \left[\begin{array}
{rrr}
1 & 0 & 0 & 0 \\
1 & 0 & 0 & 0
\end{array}\right]
$$
The preview shows up fine in Rstudio:
But when I knit to pdf I get this error message:
! LaTeX Error: \mathbf allowed only in math mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.88 \$\$ \mathbf{y}
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
How can I fix it?
Works okay if you change to an explicit math environment:
---
title: "matrix"
date: "November 2, 2016"
output:
pdf_document: default
---
\begin{equation}
\mathbf{y} = \left[\begin{array}
{r}
y_{1,1} \\
y_{4,3}
\end{array}\right]
\mathbf{X} = \left[\begin{array}
{rrrr}
1 & 0 & 0 & 0 \\
1 & 0 & 0 & 0
\end{array}\right]
\end{equation}
except you also want to fix your array alignments, otherwise
Extra alignment tab has been changed to \cr.
(you need just {r} for the first, and {rrrr} for the second)

Resources