不引用块标签有什么缺点吗?

Are there any drawbacks when chunk labels are not quoted?

knitr的创始人谢益辉writes in the official knitr chunk option documentation(本人强调):

  • (...) 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'})

据我了解,引用和未引用的块标签的结果应该始终相同。这是真的吗?或者是否存在任何(边缘)情况,其中引用与不引用块标签实际上很重要?

特别是,我想知道如果遵循 knitr 块选项文档中的以下建议,结果是否可能存在任何差异:

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

我能想到的唯一边缘情况是你的块标签包含逗号,例如 a,b。在这种情况下,它必须被引用为 'a,b',否则 a 将被视为块标签。

块标签通过内部函数自动引用 knitr:::quote_label()。您可以尝试自己找出其他可能的边缘情况:

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