<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/studying-cran-package-names/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://msperlin.github.io/2017-05-09-Studying-Pkg-Names/"> R and Finance</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> – </p>
<p>Setting a name for a CRAN package is an intimate process. Out of an<br>
infinite range of possibilities, an idea comes for a package and you<br>
spend at least a couple of days writing up and testing your code before<br>
submitting to CRAN. Once you set the name of the package, you cannot<br>
change it. You choice index your effort and, it shouldn’t be a surprise<br>
that the name of the package can improve its impact.</p>
<p>Looking at <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/available_packages_by_date.html">package<br>
names</a>,<br>
one strategy that I commonly observe is to use small words, a verb or<br>
noun, and add the letter R to it. A good example is <code>dplyr</code>. Letter <code>d</code><br>
stands for dataframe, ply is just a tool, and R is, well, you know. In a<br>
conventional sense, the name of this popular tool is informative and<br>
easy to remember. As always, the extremes are never good. A couple of<br>
bad examples of package naming are <code>A3</code>, <code>AF</code>, <code>BB</code> and so on. Googling<br>
the package name is definitely not helpful. On the other end, package<br>
<code>samplesizelogisticcasecontrol</code> provides a lot of information but it is<br>
plain unattractive!</p>
<p>Another strategy that I also find interesting is developers using names<br>
that, on first sight, are completely unrelated to the purpose of the<br>
package. But, there is a not so obvious link. One example is package<br>
<code>sandwich</code>. At first sight, I challenge anyone to figure out what it<br>
does. This is an econometric package that computes robust standard<br>
errors in a regression model. These robust estimates are also called<br>
<em>sandwich</em> estimators because the formula <a target="_blank" rel="nofollow" href="http://gosset.wharton.upenn.edu/teaching/541/sandwich_estimator.html">looks like a<br>
sandwich</a>.<br>
But, you only know that if you studied a bit of econometric theory. This<br>
strategy works because it is easier to remember things that surprise us.<br>
Another great example is package <code>janitor</code>. I’m sure you already<br>
suspect that it has something do to with data cleaning. And you are<br>
right! The message of the name is effortless and it works! The author<br>
even got the privilege of using letter R in the name.</p>
<p>While I can always hand pick good and bad examples, let’s dig deeper. In<br>
this post, we will study the names of packages available in CRAN by<br>
comparing them to the whole English vocabulary. We are going use the<br>
following datasets:</p>
<ul>
<li>List of CRAN package, available with function<br>
<code>available.packages()</code>.</li>
<li>List of English words, available at <a target="_blank" rel="nofollow" href="http://wordnet.princeton.edu/wordnet/download/standoff/">WordNet<br>
database</a>.<br>
This is a comprehensive database of English words that I once used<br>
in a<br>
<a target="_blank" rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/for.2446/full">paper</a>.<br>
It contains several tables, including all possible words from the<br>
English language.</li>
</ul>
<p>First, let’s have a look at the distribution of size (number of<br>
characters) for all packages available in CRAN:</p>
<div>
<pre><code>library(dplyr)
library(ggplot2)

# get data
df.pkgs &lt;- as.data.frame(available.packages(repos = 'https://cloud.r-project.org/')) %>%
  mutate(Package = as.character(Package),
         n.char = nchar(Package)) %>% 
  rename(pkg = Package) %>%
  select(pkg, n.char)

# plot it!
p &lt;- ggplot(df.pkgs, aes(x=n.char)) +
  geom_histogram(binwidth = 1)
print(p)
</code></pre>
</div>
<p><img alt="" src="https://i2.wp.com/msperlin.github.io/img/2017-05-09-Studying-Pkg-Names_files/figure-markdown_strict/unnamed-chunk-1-1.png?w=456" data-recalc-dims="1"></p>
<p>As I suspected, the names of CRAN packages are usually small, with an<br>
average of 5-6 characters. We have a couple of packages with more than<br>
25 characters. Let’s see their names:</p>
<div>
<pre><code>df.pkgs$pkg[df.pkgs$n.char>25]

## [1] &quot;AnglerCreelSurveySimulation&quot;   &quot;FractalParameterEstimation&quot;   
## [3] &quot;ig.vancouver.2014.topcolour&quot;   &quot;RoughSetKnowledgeReduction&quot;   
## [5] &quot;samplesizelogisticcasecontrol&quot;
</code></pre>
</div>
<p>I am sorry for the authors, but, in my opinion, I’m sure we could find<br>
better names. I am also sorry for those who are using these packages but<br>
do not use the <a target="_blank" rel="nofollow" href="https://msperlin.github.io/pafdR/basicoperations.html#using-code-completion-with-tab">autocomplete<br>
tool</a><br>
of RStudio and need to type the loooooooooong names.</p>
<p>As for my hypothesis that CRAN package have short names, let’s compare<br>
the distribution of package names against all words in the English<br>
language. For that, let’s load the WordNet database and do some<br>
calculations:</p>
<div>
<pre><code>library(RSQLite)
library(stringr)

# get data
conn &lt;- dbConnect(drv = SQLite(), 'WordNet/sqlite-31.db')
words &lt;- dbReadTable(conn, 'wordsXsensesXsynsets') %>%
  select(lemma)

# some are duplicate (same word, different types)
words &lt;- unique(words)
words$nchar &lt;- nchar(words$lemma)

# set df to plot
df.to.plot &lt;- data.frame(n.char = c(df.pkgs$n.char, words$nchar), 
                         source.char = c(rep('CRAN pkgs', nrow(df.pkgs)),
                                         rep('English Vocabulary', nrow(words))))


p &lt;- ggplot(df.to.plot, aes(x=n.char, color=source.char )) +
  geom_density(size=1) + coord_cartesian(xlim=c(0, 40))

print(p)
</code></pre>
</div>
<p><img alt="" src="https://i0.wp.com/msperlin.github.io/img/2017-05-09-Studying-Pkg-Names_files/figure-markdown_strict/unnamed-chunk-3-1.png?w=456" data-recalc-dims="1"></p>
<p>As I suspected, the distributions are very different. There is no need<br>
to apply a formal test as the visual evidence is clear: CRAN package<br>
have a tendency for shorter names.</p>
<p>Now, let’s look at the distribution of used letters in relative terms:</p>
<div>
<pre><code>library(scales)

temp &lt;- str_split(str_to_upper(df.pkgs$pkg), '')
all.chars &lt;- do.call(what = c,args = temp)
char.counts.pkg &lt;- table(all.chars)

temp &lt;- str_split(str_to_upper(words$lemma), '')
all.chars &lt;- do.call(what = c,args = temp)
char.counts.words &lt;- table(all.chars)

df.to.plot &lt;- data.frame(perc.count = c(char.counts.pkg/sum(char.counts.pkg), 
                                   char.counts.words/sum(char.counts.words)),
                         char = c(names(char.counts.pkg),
                                  names(char.counts.words)),
                         source.char = c(rep('CRAN pkgs', length(char.counts.pkg)),
                                         rep('WordNet', length(char.counts.words))))

# only keep LETTERS
idx &lt;- df.to.plot$char %in% LETTERS
df.to.plot &lt;- df.to.plot[idx, ]

p &lt;- ggplot(df.to.plot, aes(x=char, y = perc.count, color=source.char,width=.5)) +
  geom_col(position = 'dodge') + scale_y_continuous(labels = percent_format())  

print(p)
</code></pre>
</div>
<p><img alt="" src="https://i2.wp.com/msperlin.github.io/img/2017-05-09-Studying-Pkg-Names_files/figure-markdown_strict/unnamed-chunk-4-1.png?w=456" data-recalc-dims="1"></p>
<p>The result is really interesting! I was expecting far more differences<br>
in the relative use of characters. Not surprisingly, letter R is more<br>
used in package naming than in the English vocabulary. Still, the<br>
difference is not that large. Given that R is the name of the<br>
programming language, I was expecting a much greater proportion of R<br>
characters. My intuition was clearly wrong! In comparison, letters P and<br>
M have more difference in relative terms than letter R. I’m really not<br>
sure why that is. Overall, it is pretty clear the use of characters in<br>
the names of packages follow the distribution of words in the English<br>
language.</p>
<p>While the distribution of letter is similar, we find just a few package<br>
with names exactly as in the English language. For all 10524 packages<br>
found in CRAN, only 698 are an exact match of all 147478 unique words in<br>
the English vocabulary. If we can’t match them all, let’s see how far<br>
they are from the English dictionary. For that, we use package<br>
<code>stringdist</code> to compute the minimum editing distance that we can find<br>
for all package names with respect to the English vocabulary. In a<br>
nutshell, the editing distance measures how many string modifications we<br>
need in order for two strings to match each other. By computing the<br>
minimum editing distance of package’s names against the English<br>
vocabulary, we have a measure of equality. Here I’m using <code>method='lv'</code>,<br>
which seems to be the most appropriate in this study.</p>
<div>
<pre><code>my.fct &lt;- function(str.in,possible.names ){
  require(stringdist)
  #my.dist&lt;- possible.names[which.min(stringdist(str.in, possible.names ))]
  my.dist&lt;- min(stringdist(str.in, possible.names, method='lv'))
  #my.dist&lt;- min(adist(str.in, possible.names ))
  return(my.dist)
}


char.distances &lt;- pbapply::pbsapply(df.pkgs$pkg, FUN = my.fct, 
                             possible.names=words$lemma)

## Loading required package: stringdist
</code></pre>
</div>
<p>Let’s look at the results:</p>
<div>
<pre><code>p &lt;- ggplot(data.frame(char.distances), aes(x=char.distances))+
  geom_histogram(binwidth = 1) 

print(p)
</code></pre>
</div>
<p><img alt="" src="https://i2.wp.com/msperlin.github.io/img/2017-05-09-Studying-Pkg-Names_files/figure-markdown_strict/unnamed-chunk-6-1.png?w=456" data-recalc-dims="1"></p>
<p>As we can see, most of packages names are just three or four edits away.<br>
This shows how similar the choice of packages is to the English<br>
vocabulary.</p>
<p>Summing up, our data analysis shows that the names of packages are<br>
usually shorter than the words in the English language. However, when<br>
looking at distribution of used characters and editing distances, it is<br>
pretty clear that the names are based on the English language, usually<br>
with a few modifications of a base word.</p>
<p>I hope you enjoyed this post. In the next one I will explore the<br>
package’s authors and the use of comments in R code.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://msperlin.github.io/2017-05-09-Studying-Pkg-Names/"> R and Finance</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/GikYj5MAdVA"></a></div>