Rmarkdown stop generating after a paragraph - r

So my problem is that after a specific paragraph Rmarkdown doesn't generating the rest of the code and I don't know why. Note that if I delete that paragraph the program will render untill the next text paragraph and then do the same thing.
Here is a minimal markdown example with the problematic paragraph. The code block and text after the code block do not show up in the PDF.
---
title: "Proiect Regresie"
author: "Andrei Alexandru; grupa 322"
output: pdf_document
---
# Estimarea parametrilor
Considerăm modelul de regresie liniară simplă $y=\beta_{0}+\beta_{1}x +\varepsilon$ (unde x venitul provenit din vanzarile in America de Nord iar
y venitul provenit din vanzarile la nivel mondial, $\varepsilon$ este repartizat normal de medie 0 și varianță sigma p\u atrat. Estimatorii parametrilor $\beta_{0}$ \c si $\beta_{1}$ ob\c tinu\c ti prin metoda celor mai mici pătrate sunt calcula\c ti \^in R.
```{r}
mtcars
```
Some more text.

Apparently, the special characters (\c, etc.) are causing this problem. You need to specify the language using babel. Since it is a LaTeX package, you need to put it in header-includes in YAML.
Here are two examples of the changes you need to do:
\c si needs to be rewritten \c{s}i
ob\c tinu\c ti needs to be rewritten ob\c{t}inu\c{t}i
However, I can't figure out why using \^i or \^{i} does not work.
Full example:
---
title: "Proiect Regresie"
author: "Andrei Alexandru; grupa 322"
output: pdf_document
header-includes:
- \usepackage[romanian]{babel}
---
# Estimarea parametrilor
Considerăm modelul de regresie liniară simplă $y=\beta_{0}+\beta_{1}x +\varepsilon$ (unde x venitul provenit din vanzarile in America de Nord iar
y venitul provenit din vanzarile la nivel mondial, $\varepsilon$ este repartizat normal de medie 0 și varianță sigma p\u{a}trat. Estimatorii parametrilor $\beta_{0}$ \c{s}i $\beta_{1}$ ob\c{t}inu\c{t}i prin metoda celor mai mici pătrate sunt calcula\c{t}i \^{i}n R.
```{r}
mtcars
```
Some more text.

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!)

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.

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

knitr does not compile pdf

I'm new to coding and I`m trying to use knitr to print a PDF. I have installed R 3.5.3 and RStudio installed correctly as simple codes usually run.
I have both installed in the same folder as Miktex 2.9.7
As I create a new markdown file with a PDF output, incoded in UTF-8, I get the standard model text.
I've tried different encodings and reinstalled miktex several times.
When I run a code I used at my uni lab, it runs, but if I alter even 1 character on a string and save it, it wont compile the pdf anymore.
This is what I've been trying to compile:
---
title: "Lista 1"
date: "April 6, 2019"
output: pdf_document
---
```{r instalar pacotes necessarios}
# Carregando os pacotes necessários
if (!require("pacman")) install.packages("pacman")
pacman::p_load("tinytex", "tidyverse")
```
Questão 1
Use os conhecimentos adquiridos em sala de aula (e fora dela!) para realizar >as seguintes operações sobre o
banco de dados mpg:
```{r variaveis q1a}
posicao <- 100
item.a <- mpg[posicao, c("manufacturer","model")]
```
a) A partir do código acima podemos verificar que o veículo de posição `r posicao` banco de daados é um `r item.a`
```{r}
media.milhas.cidade <- mean(mpg$cty)
```
b) A partir do código acima, pode-se verificar que a média de milhas por galão na cidade é `r media.milhas.cidade`
I should just get the pdf but Rstudio prints this:
================================
processing file: lista1mkd.Rmd
|......... | 14%
ordinary text without R code
|................... | 29%
label: instalar pacotes necessarios
|............................ | 43%
ordinary text without R code
|..................................... | 57%
label: variaveis q1a
|.............................................. | 71%
inline R code fragments
# A tibble: 1 x 2
manufacturer model
<chr> <chr>
1 honda civic
|........................................................ | 86%
label: unnamed-chunk-1
|.................................................................| 100%
inline R code fragments
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS lista1mkd.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output lista1mkd.tex --template "C:\Users\CESARA~1\DOCUME~1\R\WIN-LI~1\3.5\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes"
output file: lista1mkd.knit.md
Error: Failed to compile lista1mkd.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips.
In addition: Warning message:
In readLines(logfile) : incomplete final line found on 'lista1mkd.log'
Execution halted

First name and last name inverted in bibliography r markdown

I got a problem using R-markdown to write my master's work. I am using the papaja package. Everything's fine except that when I knit my document to produce a pdf the first name of the author in my bibliography are BEFORE the last name. Here is a little reproducible example of my problem. Here is the r-makrdown content:
---
title: "The title"
shorttitle: "Title"
author:
- name: First Author
affiliation: 1
corresponding: yes # Define only one corresponding author
address: Postal address
email: my#email.com
- name: Ernst-August Doelle
affiliation: "1,2"
affiliation:
- id: 1
institution: Wilhelm-Wundt-University
- id: 2
institution: Konstanz Business School
abstract: |
Enter abstract here (note the indentation, if you start a new paragraph).
note: |
Complete departmental affiliations for each author (note the indentation, if you start a new paragraph).
Enter author note here.
keywords: "keywords"
wordcount: X
class: man
lang: american
figsintext: yes
lineno: yes
bibliography:
- r-references.bib
output: papaja::apa6_pdf
---
```{r message = FALSE, warning = FALSE}
library("papaja")
apa_prepare_doc() # Prepare document for rendering
```
[#R-papaja]
# References
```{r create_r-references}
r_refs(file = "test-references.bib")
```
\setlength{\parindent}{-0.5in}
\setlength{\leftskip}{0.5in}
\setlength{\parskip}{8pt}
And here are my references which are in the "test-references.bib" file:
%% This BibTeX bibliography file was created using BibDesk.
%% http://bibdesk.sourceforge.net/
%% Created for Lucien at 2015-12-09 13:45:03 +0100
%% Saved with string encoding Unicode (UTF-8)
#Manual{R-base,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2015},
url = {https://www.R-project.org/},
}
#Manual{R-papaja,
author = {Frederik Aust and Marius Barth},
title = {papaja: Create APA manuscripts with RMarkdown},
year = {2015},
note = {R package version 0.1.0.9054},
url = {https://github.com/crsh/papaja},
}
The output in the pdf for the reference is:
Frederik Aust and Marius Barth.papaja: Create APA manuscripts with RMarkdown, 2015.20URL https://github.com/crsh/papaja. R package version 0.1.0.9054.
And I expect:
Aust Frederik and Barth Marius .papaja: Create APA manuscripts with RMarkdown, 2015.20URL https://github.com/crsh/papaja. R package version 0.1.0.9054.
Your paper was probably already due... Anyway. You should have the authors in the format Lastname, Firstname [and Lastname, Firstname]*.
In your case:
#Manual{R-papaja,
author = {Aust, Frederik and Barth, Marius},
title = {papaja: Create APA manuscripts with RMarkdown},
year = {2015},
note = {R package version 0.1.0.9054},
url = {https://github.com/crsh/papaja},
}

Resources