【问题标题】:Why does my table of contents specifications not work properly? From Distill for R Markdown为什么我的目录规范不能正常工作?来自 R Markdown 的 Distill
【发布时间】:2021-10-21 23:36:19
【问题描述】:

感谢您的帮助!

我在将目录 (toc) 放入我的 Rmarkdown 时遇到问题

我已经使用以下 YAML 设置了文档.. 根据 https://bookdown.org/yihui/rmarkdown/html-document.htmlhttps://rstudio.github.io/distill/basics.html#table-of-contents 我应该可以得到一个不错的目录。但这对我不起作用..有什么想法吗?

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

我的文档内容如下:

```{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")
```

相反,我得到这个里面什么都没有。

..我的目录中没有内容??

【问题讨论】:

    标签: r r-markdown markdown r-distill


    【解决方案1】:

    我认为只是格式化 YAML 的问题。当我粘贴你的时,我得到了和你完全相同的结果。但是,如果我这样格式化:

    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
    

    我通过 TOC 获得了这个:

    显然,我没有添加您拥有的图像。

    【讨论】:

    • 没错,@Juan David Leongomez,“缩进在 YAML 中很重要,所以不要忘记正确缩进顶部字段的子字段。请参阅 Xie (2016) 的 Appendix B.2显示 YAML 语法的简单示例”。引用自:bookdown.org/yihui/rmarkdown/basics.html
    • 非常感谢@juan 和@radovan!
    • @juan 感谢您的帮助。现在,我的一个distill::distill_article: 网页在构建网站时出现错误。错误是Error in eval(xfun::parse_only(name)) : object 'toc_float' not found Calls: &lt;Anonymous&gt; ... output_format_from_yaml_front_matter -&gt; create_output_format_function -&gt; eval -&gt; eval In addition: Warning message: Ignoring unknown aesthetics: x, y Execution halted Exited with status 1.
    • 我不明白这个错误:Error in eval(xfun::parse_only(name)) : object 'toc_float' not found。我已经指定了我应该做的一切。对于我的另外两个页面,没有问题。只为这个..
    • 感谢大家在这个问题上努力帮助我。最终,我决定把整个东西变成一个蒸馏网站,在从一个自动生成 YAML 的 GitHub 存储库开始之后,这个问题就不再存在了。不过仍然是个谜。。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    相关资源
    最近更新 更多