Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Today I made a confession on Twitter: I told the world I had spent my whole career not naming chunks in RMarkdown documents. Even if I had said one should name them when teaching RMarkdown. But it was also a tweet for showing off since I was working on the first manuscript with named chunks and loving it. I got some interesting reactions to my tweet, including one that made me feel better about myself (sorry Thomas), and other ones that made me feel like phrasing why one should name RMarkdown chunks.

Hadley Wickham asked whether chunks were pets or livestock, as in his analogy for models. Livestock chunks are identified by numbers, not names, in the case of chunks defined by position. I now think we have good reason to consider them as pets and here’s why…

My fur sibling does come if you call him

• Navigating the RMarkdown document. You can yell a dog’s name and it’ll come to you. Well hopefully… In any case in RStudio you can actually navigate named chunks fairly easily.

Chunk down! Don’t worry, Mowgli was just taking a nap.

• Reading error reports or progress of knitting. It’s much easier to find which chunk exactly is down, or to see how well knitting is going, with chunk names.

• Moving chunks around, adding some. In particular, cache results are saved by chunk name or position, so caching is more efficient with named chunks. With unnamed chunks you might end up unwillingly re-running that long slow chunk!

When you’re cool and you know it

Truth be told maybe I won’t always name my chunks, e.g. in blog posts, but for manuscripts and other bigger projects I think it’s the way to go. And now I need to go read more about autodep in knitr, at least to distract myself for missing my fur sibling too much!