<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/5-easy-package-information/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://dirk.eddelbuettel.com/blog/2017/04/14#005_easy_package_info"> Thinking inside the box </a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Welcome to the fifth post in the <em>recklessly rambling R rants</em> series, or <span><em>R</em><sup>4</sup></span> for short.</p>
<p>The <a target="_blank" rel="nofollow" href="http://dirk.eddelbuettel.com/blog/2017/04/06#003_follow_r-devel">third post</a> showed an easy way to follow R development by monitoring (curated) changes on the NEWS file for the development version r-devel. As a concrete example, I mentioned that it has shown a nice new function (<code>tools::CRAN_package_db()</code>) coming up in R 3.4.0. Today we will build on that.</p>
<p>Consider the following short snippet:</p>
<div>
<pre><code><span>library</span>(data.table)

getPkgInfo &lt;-<span> </span>function() {
    if (<span>exists</span>(<span>&quot;tools::CRAN_package_db&quot;</span>)) {
        dat &lt;-<span> </span>tools::<span>CRAN_package_db</span>()
    } else {
        tf &lt;-<span> </span><span>tempfile</span>()
        <span>download.file</span>(<span>&quot;https://cloud.r-project.org/src/contrib/PACKAGES.rds&quot;</span>, tf, <span>quiet=</span><span>TRUE</span>)
        dat &lt;-<span> </span><span>readRDS</span>(tf)              <span># r-devel can now readRDS off a URL too</span>
    }
    dat &lt;-<span> </span><span>as.data.frame</span>(dat)
    <span>setDT</span>(dat)
    dat
}</code></pre>
</div>
<p>It defines a simple function <code>getPkgInfo()</code> as a wrapper around said new function from R 3.4.0, ie <code>tools::CRAN_package_db()</code>, and a fallback alternative using a tempfile (in the automagically cleaned R temp directory) and an explicit download and read of the underlying RDS file. As an aside, just this week the r-devel NEWS told us that such <code>readRDS()</code> operations can now read directly from URL connection. Very nice—as RDS is a fantastic file format when you are working in R.</p>
<p>Anyway, back to the RDS file! The snippet above returns a <a target="_blank" rel="nofollow" href="http://r-datatable.com/">data.table</a> object with as many rows as there are packages on CRAN, and basically all their (parsed !!) DESCRIPTION info and then some. A gold mine!</p>
<p>Consider this to see how many package have a dependency (in the sense of Depends, Imports or LinkingTo, but not Suggests because <a target="_blank" rel="nofollow" href="http://dirk.eddelbuettel.com/blog/2017/03/22/">Suggests != Depends</a>) on Rcpp:</p>
<div>
<pre><code>R><span> </span>dat &lt;-<span> </span><span>getPkgInfo</span>()
R><span> </span>rcppRevDepInd &lt;-<span> </span><span>as.integer</span>(tools::<span>dependsOnPkgs</span>(<span>&quot;Rcpp&quot;</span>, <span>recursive=</span><span>FALSE</span>, <span>installed=</span>dat))
R><span> </span><span>length</span>(rcppRevDepInd)
[<span>1</span>] <span>998</span>
R></code></pre>
</div>
<p>So exciting—we will hit 1000 within days! But let’s do some more analysis:</p>
<div>
<pre><code>R><span> </span>dat[ rcppRevDepInd, RcppRevDep :<span>=</span><span> </span><span>TRUE</span>]  <span># set to TRUE for given set</span>
R><span> </span>dat[ RcppRevDep==<span>TRUE</span>, <span>1</span>:<span>2</span>]
           Package Version
  <span>1</span>:<span> </span>ABCoptim  <span>0.14.0</span>
  <span>2</span>:<span> </span>AbsFilterGSEA     <span>1.5</span>
  <span>3</span>:<span> </span>acc   <span>1.3.3</span>
  <span>4</span>:<span> </span>accelerometry   <span>2.2.5</span>
  <span>5</span>:<span> </span>acebayes   <span>1.3.4</span>
 ---<span> </span>
<span>994</span>:<span> </span>yakmoR   <span>0.1.1</span>
<span>995</span>:<span> </span>yCrypticRNAs  <span>0.99.2</span>
<span>996</span>:<span> </span>yuima   <span>1.5.9</span>
<span>997</span>:<span> </span>zic     <span>0.9</span>
<span>998</span>:<span> </span>ziphsmm   <span>1.0.4</span>
R></code></pre>
</div>
<p>Here we index the reverse dependency using the vector we had just computed, and then that new variable to subset the <code>data.table</code> object. Given the aforementioned <em>parsed</em> information from all the DESCRIPTION files, we can learn more:</p>
<div>
<pre><code>R><span> </span>## likely false entries
R><span> </span>dat[ RcppRevDep==<span>TRUE</span>, ][NeedsCompilation!=<span>&quot;yes&quot;</span>, <span>c</span>(<span>1</span>:<span>2</span>,<span>4</span>)]
            Package Version                                                                         Depends
 <span>1</span>:<span> </span>baitmet   <span>1.0.0</span>                                                           Rcpp, <span>erah</span> (>=<span> </span><span>1.0.5</span>)
 <span>2</span>:<span> </span>bea.R   <span>1.0.1</span>                                                        <span>R</span> (>=<span> </span><span>3.2.1</span>), data.table
 <span>3</span>:<span> </span>brms   <span>1.6.0</span>                     <span>R</span> (>=<span> </span><span>3.2.0</span>), <span>Rcpp</span> (>=<span> </span><span>0.12.0</span>), <span>ggplot2</span> (>=<span> </span><span>2.0.0</span>), methods
 <span>4</span>:<span> </span>classifierplots   <span>1.3.3</span>                             <span>R</span> (>=<span> </span><span>3.1</span>), <span>ggplot2</span> (>=<span> </span><span>2.2</span>), <span>data.table</span> (>=<span> </span><span>1.10</span>),
 <span>5</span>:<span> </span>ctsem   <span>2.3.1</span>                                           <span>R</span> (>=<span> </span><span>3.2.0</span>), <span>OpenMx</span> (>=<span> </span><span>2.3.0</span>), Rcpp
 <span>6</span>:<span> </span>DeLorean   <span>1.2.4</span>                                                  <span>R</span> (>=<span> </span><span>3.0.2</span>), <span>Rcpp</span> (>=<span> </span><span>0.12.0</span>)
 <span>7</span>:<span> </span>erah   <span>1.0.5</span>                                                               <span>R</span> (>=<span> </span><span>2.10</span>), Rcpp
 <span>8</span>:<span> </span>GxM     <span>1.1</span>                                                                              <span>NA</span>
 <span>9</span>:<span> </span>hmi   <span>0.6.3</span>                                                                    <span>R</span> (>=<span> </span><span>3.0.0</span>)
<span>10</span>:<span> </span>humarray     <span>1.1</span> <span>R</span> (>=<span> </span><span>3.2</span>), <span>NCmisc</span> (>=<span> </span><span>1.1.4</span>), <span>IRanges</span> (>=<span> </span><span>1.22.10</span>),\<span>nGenomicRanges</span> (>=<span> </span><span>1.16.4</span>)
<span>11</span>:<span> </span>iNextPD   <span>0.3.2</span>                                                                    <span>R</span> (>=<span> </span><span>3.1.2</span>)
<span>12</span>:<span> </span>joinXL   <span>1.0.1</span>                                                                    <span>R</span> (>=<span> </span><span>3.3.1</span>)
<span>13</span>:<span> </span>mafs   <span>0.0.2</span>                                                                              <span>NA</span>
<span>14</span>:<span> </span>mlxR   <span>3.1.0</span>                                                           <span>R</span> (>=<span> </span><span>3.0.1</span>), ggplot2
<span>15</span>:<span> </span>RmixmodCombi     <span>1.0</span>              <span>R</span>(>=<span> </span><span>3.0.2</span>), <span>Rmixmod</span>(>=<span> </span><span>2.0.1</span>), <span>Rcpp</span>(>=<span> </span><span>0.8.0</span>), methods,\ngraphics
<span>16</span>:<span> </span>rrr   <span>1.0.0</span>                                                                    <span>R</span> (>=<span> </span><span>3.2.0</span>)
<span>17</span>:<span> </span>UncerIn2     <span>2.0</span>                          <span>R</span> (>=<span> </span><span>3.0.0</span>), sp, RandomFields, automap, fields, gstat
R><span> </span></code></pre>
</div>
<p>There are a full seventeen packages which claim to depend on Rcpp while not having any compiled code of their own. That is likely false—but I keep them in my counts, however relunctantly. A CRAN-declared Depends: is a Depends:, after all.</p>
<p>Another nice thing to look at is the total number of package that declare that they need compilation:</p>
<div>
<pre><code>R><span> </span>## number of packages with compiled code
R><span> </span>dat[ , .(<span>N=</span>.N), by=NeedsCompilation]
   NeedsCompilation    N
<span>1</span>:<span> </span>no <span>7625</span>
<span>2</span>:<span> </span>yes <span>2832</span>
<span>3</span>:<span> </span>No    <span>1</span>
R></code></pre>
</div>
<p>Isn’t that awesome? It is 2832 out of (currently) 10458, or about 27.1%. Just over one in four. Now the 998 for Rcpp look even better as they are about 35% of all such packages. In order words, a little over one third of all packages with compiled code (which may be legacy C, Fortran or C++) use Rcpp. Wow.</p>
<p>Before closing, one shoutout to <a target="_blank" rel="nofollow" href="https://www.dirk-schumacher.net/">Dirk Schumacher</a> whose <a target="_blank" rel="nofollow" href="https://cran.r-project.org/package=thankr">thankr</a> which I made the center of <a target="_blank" rel="nofollow" href="http://dirk.eddelbuettel.com/blog/2017/04/08#004_simpler_shoulders">the last post</a> is now on CRAN. As a mighty fine and slim micropackage without external dependencies. Neat.</p>
<p>
This post by <a target="_blank" rel="nofollow" href="http://dirk.eddelbuettel.com/">Dirk Eddelbuettel</a> originated on his <a target="_blank" rel="nofollow" href="http://dirk.eddelbuettel.com/blog/">Thinking inside the box</a> blog. Please report excessive re-aggregation in third-party for-profit settings.</p>
<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://dirk.eddelbuettel.com/blog/2017/04/14#005_easy_package_info"> Thinking inside the box </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/NQ9mvcgnt0M"></a></div>