Are there any drawbacks when chunk labels are not quoted?

Viewed 51

Yihui Xie, the creator of knitr, writes in the official knitr chunk option documentation (emphasis by me):

  • (...) in theory, the chunk label should be quoted as well, but for the sake of convenience it will be automatically quoted if you did not quote it (e.g. ```{r, 2a} will become ```{r, '2a'})

As I understand this, the results of quoted and unquoted chunk labels should always be the same. Is this really true? Or might there be any (edge) cases where quoting vs. not quoting the chunk labels actually matters?

Especially, I'd like to know if there might be any differences in results if one adheres to the following recommendation also found in the knitr chunk option documentation:

(...) in general it is recommended to use alphabetic characters with words separated by - and avoid other characters (...)

1 Answers

The only edge case I can think of is when your chunk label contains a comma, e.g., a,b. In this case, it has to be quoted as 'a,b', otherwise a will be treated as the chunk label.

Chunk labels are automatically quoted via the internal function knitr:::quote_label(). You may try to find out other possible edge cases by yourself:

> knitr:::quote_label("a")
[1] "'a'"
> knitr:::quote_label("a,b")
[1] "'a',b"
> knitr:::quote_label('"a,b"')
[1] "\"a,b\""
> knitr:::quote_label("a a a,b=1")
[1] "'a a a',b=1"
> knitr:::quote_label("a},b=1")
[1] "'a}',b=1"
Related