1

Thank you for your help!

I am having troubles with getting the table of contents (toc) into my Rmarkdown

I have set up the document with the following YAML.. and according to https://bookdown.org/yihui/rmarkdown/html-document.html and https://rstudio.github.io/distill/basics.html#table-of-contents I should be able to get a nice toc. But it does not work for me.. Any idea?

---
title: Evidence for Resilient Agriculture ERA
description: | 
  Using tidymodels to Explore Agroforestry Data 
date: "7/23/2021"
author:
  - first_name: "Kamau"
    last_name: "Lindhardt"
    url: https://www.linkedin.com/in/magnus-kamau-lindhardt/
    affiliation: World Agroforestry Centre, Nairobi
    affiliation_url: https://www.worldagroforestry.org
  - name: "Peter Steward"
bibliography: library.bib
csl: frontiers-in-ecology-and-the-environment.csl
output: distill::distill_article
toc: true
toc_float: 
collapsed: false
smooth_scroll: true
number_sections: true
toc_depth: 3
code_folding: true
---

With the content of my document like this:

```{r setup, include=FALSE, code_folding=FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  warning = FALSE,
  message = FALSE,
  comment = "#",
  R.options = list(width = 60)
)
```


```{r ERA and ICRAF logo, fig.align='center', size=20, code_folding=TRUE}
library(cowplot)
ggdraw() + 
  draw_image("/Users/kamaulindhardt_1/Library/Mobile Documents/com~apple~CloudDocs/MSc Wageningen University /Internship ICRAF-ERA/R notes, codes and content/ERA_AGROFORESTRY/./IMAGES/ERA_logo_color.png", width = 0.5) + 
  draw_image("/Users/kamaulindhardt_1/Library/Mobile Documents/com~apple~CloudDocs/MSc Wageningen University /Internship ICRAF-ERA/R notes, codes and content/ERA_AGROFORESTRY/./IMAGES/ICRAF_logo.png", width = 0.5, x = 0.5)
```




# Libraries
```{r setup bookdown, include=TRUE}
library(bookdown)
library(tidyverse)
library(data.table)
library(kableExtra)
library(knitr)
library(here)
#library(cowplot)
```



# Section
## Subsection
### Subsubsection
#### Subsubsubsection

## Quarterly Results {.tabset}

some text

text 1

```{r include=FALSE, layout="l-screen-inset"}
rmarkdown::paged_table(mtcars)
```

```{r, dpi = 200, fig.align='center', fig.cap= 'first'}
plot(cars)
```


text 2

# Section

```{r, fig.align='center', fig.cap= 'second'}
plot(pressure)
```

text 3

# Section 4

## Subsection 4.1

```{r fig.align='center', tidy=TRUE, code_folding=TRUE}
library(ggplot2)
#qplot(x = Sepal.Length, y = Sepal.Width, data = iris, 
#      xlab="Sepal Length", ylab="Sepal Width", 
#      main="Sepal Length-Width", color=Species, shape=Species)

scatter <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) 
scatter + geom_point(aes(color=Species, shape=Species)) +
  xlab("Sepal Length") +  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width")
```

Instead, I get this with nothing inside.

Screenshot of the knitted document - has no content in the toc

..and there is no content in my table of content??

1 Answers1

3

I think is just a matter of formatting your YAML. When I pasted yours, I had the exact same result as you. However, if I format it like this:

title: Evidence for Resilient Agriculture ERA
description: | 
  Using tidymodels to Explore Agroforestry Data 
date: "7/23/2021"
author:
  - first_name: "Kamau"
    last_name: "Lindhardt"
    url: https://www.linkedin.com/in/magnus-kamau-lindhardt/
    affiliation: World Agroforestry Centre, Nairobi
    affiliation_url: https://www.worldagroforestry.org
  - name: "Peter Steward"
bibliography: library.bib
csl: frontiers-in-ecology-and-the-environment.csl
output: 
  distill::distill_article:
    toc: true
    number_sections: true
    toc_depth: 4
    code_folding: true
  toc_float: 
    collapsed: false
    smooth_scroll: true

I obtain this, with the TOC:

enter image description here

Obviously, I didn't add the images you have.

  • 4
    Exactly, @Juan David Leongomez, "indentation matters in YAML, so do not forget to indent the sub-fields of a top field properly. See the [Appendix B.2](https://bookdown.org/yihui/bookdown/r-markdown.html) of Xie (2016) for a few simple examples that show the YAML syntax". Cited from: https://bookdown.org/yihui/rmarkdown/basics.html – Radovan Miletić Aug 22 '21 at 07:43
  • 2
    @juan I appreciate you help. Now I have the issue that One of my `distill::distill_article:` webpages get an error when I build the website. The error is `Error in eval(xfun::parse_only(name)) : object 'toc_float' not found Calls: ... output_format_from_yaml_front_matter -> create_output_format_function -> eval -> eval In addition: Warning message: Ignoring unknown aesthetics: x, y Execution halted Exited with status 1.` – Kamau Lindhardt Aug 23 '21 at 23:43
  • 1
    I don't understand this error: `Error in eval(xfun::parse_only(name)) : object 'toc_float' not found`. I have specified everything exactly I it should. And for my two other pages there is no problem. Only for this one.. – Kamau Lindhardt Aug 23 '21 at 23:45
  • Also see my post on GitHub repo [**rstudio/distill**](https://github.com/rstudio/distill/issues/398) – Kamau Lindhardt Aug 24 '21 at 00:10
  • @MagnusKamauKatanaLindhardt wow, that's a mystery. I tried to find info on that error online, but couldn't find any, and it's not an error I can reproduce with the info you have provided here and/or on your [github issue](https://github.com/rstudio/distill/issues/398). It seems that [@apreshill](https://github.com/apreshill) has more knowledge about this, so I hope she can provide a solution. – Juan David Leongomez Aug 25 '21 at 00:43
  • 1
    Thank everyone for trying hard to help me on this issue. Eventually, I decided to turn the whole thing into a distill website and after starting from a GitHub repo with automatically generated YAML the issue is no longer there.. Still a mystery though.. – Kamau Lindhardt Aug 25 '21 at 10:49