R-Markdown no longer knitting

Asked by At

Over the past few years I have created an extensive markdown file with my notes on R. Today it no longer knits properly and none of the back-up versions knit properly either. The output is a cross between proper output and a listing of the code; sometimes prefixed with ##.

---
title: 'The R Companion'
fontsize: 11pt
toc: true
toc_depth: 4
geometry: "top = 2cm, bottom = 1.5cm, left = 2cm, right = 1.5cm"
output: pdf_document

---
\pagebreak

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy.opts=list(width.cutoff=60),tidy=TRUE)
knitr::opts_chunk$set(fig.height = 3.5, fig.width = 7)

library(readr)
library(ggplot2)
library(knitr)
library(kableExtra)
library(lubridate)
library(dplyr)
library(tibble)
library(ggthemes)
library(RColorBrewer)
```

###Basic Data Manipulation

####Vector creation 
```{r}
a <- 1:5
b <- 6:10
c <- append(a,b)
print(c)
# Append after c[4].
append(c, 4.5, after=4)
# Append before c[0].
append(c, c(-1, 0), after = 0)
```

The output (below) has only two of 15 TOC listings, the headers have not been knitted, and the outputs are incomplete/wrong. RStudio 1.2.1335, R 3.6.0., Rmarkdown 1.12. Thanks.

The R Companion
Contents
Creating and tidying data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 GraphicsI:Plot,axes,titleandlegend. .............................. 20
1
###Basic Data Manipulation ####Vector creation
## [1] 1 2 3 4 5 6 7 8 910
##  [1]  1.0  2.0  3.0  4.0  4.5  5.0  6.0  7.0  8.0  9.0 10.0
##  [1] -1  0  1  2  3  4  5  6  7  8  9 10   

1 Answers

0
Community On

Try installing the formatR package. It did not work for me until I installed it. I just ran your code and here is the output I get in a word doc knit. Is this what you are looking for?

The R Companion

Basic Data Manipulation
Vector creation
a <- 1:5
b <- 6:10
c <- append(a, b)
print(c)
##  [1]  1  2  3  4  5  6  7  8  9 10
# Append after c[4].
append(c, 4.5, after = 4)
##  [1]  1.0  2.0  3.0  4.0  4.5  5.0  6.0  7.0  8.0  9.0 10.0
# Append before c[0].
append(c, c(-1, 0), after = 0)
##  [1] -1  0  1  2  3  4  5  6  7  8  9 10