Search code examples
rbookdown

How to count words in bookdown


How can I count the number of words in a bookdown document?

(I've tried knitting to PDF and then counting the words in the PDF, but solutions for that are surprisingly unwieldy for me).


Solution

  • wordcountaddin::word_count('bookdown-demo.Rmd')
    

    wordcountaddin is an RStudio add-in. When you knit a bookdown set of files, such as the bookdown-demo, it combines them into bookdown-demo.Rmd, so you can call wordcountaddin::word_count on that. The count ignores YAML and other code chunks and inline code. Also, because References are not included in the .Rmd file, the word count won't count those either.

    If bookdown-demo.Rmd was deleted in the book creation process, you need to add delete_merged_file: false to _bookdown.yml