benmarwick / wordcountaddin

Word counts and readability statistics in R markdown documents
Other
337 stars 33 forks source link

`readbility()` does not work when called before `textstats()` #35

Closed hturner closed 2 years ago

hturner commented 5 years ago

Thanks for the nice add-in, I was looking for something to compute readability scores and it's nice to have the word count as a bonus!

The readability function works fine if I call it after the word count function (text_stats()). But if I call the readability function without calling text_stats() earlier in the session, then I get the following error:

wordcountaddin:::readability()
#> Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'readability' for signature '"NULL"'

Created on 2019-09-21 by the reprex package (v0.3.0)

mcguinlu commented 2 years ago

Seeing as I am on a working on some other fixes anyways, I said I would take a look at this (hope that's okay @benmarwick!)

This is related to the issue described and fixed in #13, where the necessary korPus language package (in this case "en") was missing, causing koRpus:::tokenize() to fail.

It was fixed at the time for the text_stats() function by requiring the "en" language package when the text_stats() function is called (which explains why the bug doesn't appear if you call text_stats() before readability()). However, a similar fix was not implemented for the readability() function.

This is addressed as part of #48 - the readability() function now similarly installs the relevant language package, and so will work in a brand new session without needing to call text_stats() first.