yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

`label` chunk option shouldn't be stored as a named vector in hashpipe chunk comment options #2280

Closed gadenbuie closed 10 months ago

gadenbuie commented 10 months ago

Issue

When the chunk label is declared using a hashpipe chunk comment option, it becomes a named vector, essentially $label = c(label = "chunk-label").

I noticed this because it breaks some assumptions in learnr (see rstudio/learnr#795) that I will fix there, but I think it's worth fixing this inconsistency directly in knitr.

Reprex

Minimal reprex ````markdown --- title: "Label shouldn't be named" output: github_document --- ```{r normal} #| echo: false ``` ```{r} #| label: hash-yaml #| echo: false ``` ```{r} #| hash-knitr, echo = FALSE ``` ```{r} knitr::knit_code$get("normal") knitr::knit_code$get("hash-yaml") knitr::knit_code$get("hash-knitr") ``` ````
```{r normal}
#| echo: false

``` r
knitr::knit_code$get("normal")
## [1] ""
## attr(,"chunk_opts")
## attr(,"chunk_opts")$label
## [1] "normal"
## 
## attr(,"chunk_opts")$echo
## [1] FALSE
```{r}
#| label: hash-yaml
#| echo: false

``` r
knitr::knit_code$get("hash-yaml")
## [1] ""
## attr(,"chunk_opts")
## attr(,"chunk_opts")$label
##       label 
## "hash-yaml" 
## 
## attr(,"chunk_opts")$echo
## [1] FALSE
```{r}
#| hash-knitr, echo = FALSE

``` r
knitr::knit_code$get("hash-knitr")
## [1] ""
## attr(,"chunk_opts")
## attr(,"chunk_opts")$label
##        label 
## "hash-knitr" 
## 
## attr(,"chunk_opts")$echo
## [1] FALSE
cderv commented 10 months ago

Thanks for catching this @gadenbuie !

github-actions[bot] commented 4 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.