Let’s load two cool libraries and create sample texts.

Number of Characters

Number of Words

How str_count  handles the ‘ might get a misleading result. I believe str_count  will replace ‘ with space which results in extra word. So, to correctly count the word, we probably need to use str_replace_all  before using  str_count

Strigi Function

Stringi  has cool function:  stri_stats_latex .

With just one function, you get all. The only disadvantage of stri_stats_latex  is we need to specify what observation to count. If we were to…

Yep… not too good. So, another way to circumvent is to use apply .