Skip to content

duplicate chunk labels emit error #408

@LiNk-NY

Description

@LiNk-NY

Hi!

Thanks for the great resource the cookbook is.

This section in the cookbook states that one can use the same chunk label in another chunk.
https://bookdown.org/yihui/rmarkdown-cookbook/reuse-chunks.html#same-label

When I try doing this in practice, I get an error.
Here is an example with a file test.Rmd:

---
title: "Testing Rmd Format"
vignette: |
  %\VignetteIndexEntry{Testing Rmd Format}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r loading, eval=FALSE}
# this is a chunk
1 + 1
```

```{r loading, eval=TRUE}

```

Leads to the error:

> rmarkdown::render("test.Rmd")
processing file: test.Rmd
Error in parse_block(g[-1], g[1], params.src, markdown_mode) : 
  Duplicate chunk label 'loading', which has been used for the chunk:
# this is a chunk
1 + 1

The error also occurs when running R CMD build on a package.

PS. I am aware of options(knitr.duplicate.label = 'allow') but this is not possible for external build systems (e.g., CRAN).

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions