编写 Rmarkdown 文档时如何删除代码块的标签?

How do I remove label of code chunk when knitting Rmarkdown document?

我的 YAML 如下所示:

---
title: "Title"
author: "AS"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  pdf_document: bookdown::pdf_document2
bibliography: references.json
header-includes:
   \usepackage{float}
 \floatplacement{figure}{H}
---

我的代码块如下所示:

{r summary table for employment in the agricultural sector, echo =FALSE}
kable(
  agrisum020406,
  booktabs = TRUE,
  digits = 2,
  col.names = c('Working in the Agricultural Sector?', 'Male', 'Female', 'Male', 'Female', 'Male', 'Female', '2002-2004', '2002-2006', '2002-2004', '2002-2006'),
  caption = "Changes in Proportion of Workers in the Agricultural Sector, by Gender") %>% 
  add_header_above(c(" " = 1, "2001" = 2, "2003" = 2, "2005" =2, "Change rate (F)" = 2, "Change rate (M)" = 2)) %>% 
  kable_styling(latex_options = c("striped", "hold_position", "scale_down"))

然而,knitted 文档显示如下:

如何删除“(#tab:农业部门就业摘要)”部分?

谢谢

我不知道为什么,但是,通常块名称不喜欢空格,最好使用破折号来分隔单词。这似乎有效...

请注意,我从 YAML header 中删除了 bibliography: references.json 以使答案可重现。

---
title: "Title"
author: "AS"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  pdf_document: bookdown::pdf_document2

header-includes:
   \usepackage{float}
 \floatplacement{figure}{H}
---

```{r summary-table-for-employment-in-the-agricultural-sector, echo =FALSE}

library(kableExtra)

kable(
  mtcars[1:5, ],
  booktabs = TRUE,
  digits = 2,
  row.names = "TRUE",
  col.names = c('Working in the Agricultural Sector?', 'Male', 'Female', 'Male', 'Female', 'Male', 'Female', '2002-2004', '2002-2006', '2002-2004', '2002-2006'),
  caption = "Changes in Proportion of Workers in the Agricultural Sector, by Gender") |> 
 add_header_above(c(" " = 1, "2001" = 2, "2003" = 2, "2005" =2, "Change rate (F)" = 2, "Change rate (M)" = 2)) |>
 kable_styling(latex_options = c("striped", "hold_position", "scale_down"))

```