Pets or livestock? Naming your RMarkdown chunks

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

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

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!