<p>I am happy to say that the latest issue of <em>The R Journal</em> <a rel="nofollow" href="https://journal.r-project.org/archive/2017/RJ-2017-058/index.html" target="_blank">includes a paper<br>
describing rentrez</a>,<br>
the rOpenSci package for retrieving data from the National Center for Biotechnology Information<br>
(NCBI).</p>
<p><a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/" target="_blank">The NCBI</a> is one of the most important sources of biological data. The centre<br>
provides access to information on 28 million scholarly articles through PubMed and 250<br>
million DNA sequences through GenBank. More importantly, records in the <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/guide/all/#databases" target="_blank">50 public<br>
databases</a> maintained by the NCBI are strongly cross-referenced. As a result, it is<br>
possible to pinpoint searches using almost 2 million taxonomic names or a<br>
<a rel="nofollow" href="https://www.nlm.nih.gov/mesh/" target="_blank">controlled vocabulary with 270,000 terms</a>.<br>
<code>rentrez</code> has been designed to make it easy to search for and download NCBI<br>
records and download them from within an R session.</p>
<p>The paper and the <a rel="nofollow" href="https://cran.r-project.org/web/packages/rentrez/vignettes/rentrez_tutorial.html" target="_blank">package vignette</a><br>
both describe typical usages of <code>rentrez</code>. I though it might be fun to use this<br>
post to find out where papers describing R packages are published these days.<br>
Although PubMed only covers journals in the biological sciences, searching that<br>
database will at least give us an idea of which journals like to publish these<br>
sorts of papers. Here we use the <code>entrez_search</code> and <code>entrez_summary</code> functions<br>
to get some information on all of the papers published in 2017 with the term<br>
‘R package’ in their title:</p>
<pre><code>library(rentrez)

pkg_search &lt;- entrez_search(db=&quot;pubmed&quot;, 
                            term=&quot;(R Package[TITLE]) AND (2017[PDAT])&quot;, 
                            use_history=TRUE)
pkg_summs &lt;- entrez_summary(db=&quot;pubmed&quot;, web_history=pkg_search$web_history)
pkg_summs
</code></pre>
<pre><code>List of  96 esummary records. First record:

 $`29512507`
esummary result with 42 items:
 [1] uid               pubdate           epubdate          source           
 [5] authors           lastauthor        title             sorttitle        
 [9] volume            issue             pages             lang             
[13] nlmuniqueid       issn              essn              pubtype          
[17] recordstatus      pubstatus         articleids        history          
[21] references        attributes        pmcrefcount       fulljournalname  
[25] elocationid       doctype           srccontriblist    booktitle        
[29] medium            edition           publisherlocation publishername    
[33] srcdate           reportnumber      availablefromurl  locationlabel    
[37] doccontriblist    docdate           bookname          chapter          
[41] sortpubdate       sortfirstauthor  
</code></pre>
<p>As you can tell from the output above, you can get a lot of information from<br>
these summary records. In this case, we are interested in the journals in which<br>
these papers appear. We can use the helper function <code>extract_from_esummary</code><br>
to isolate the ‘source’ of each paper, then use <code>table</code> to count up the frequency<br>
of each journal.</p>
<pre><code>library(ggplot2)

journals &lt;- extract_from_esummary(pkg_summs, &quot;source&quot;)
journal_freq &lt;- as.data.frame(table(journals, dnn=&quot;journal&quot;), responseName=&quot;n.papers&quot;)
ggplot(journal_freq, aes(reorder(journal, n.papers), n.papers)) + 
    geom_point(size=2) + 
    coord_flip() + 
    scale_y_continuous(&quot;Number of papers&quot;) +
    scale_x_discrete(&quot;Journal&quot;) +
    theme_bw() +
    ggtitle(&quot;Venues for papers describing R Packages in 2017&quot;) 
</code></pre>
<p><img alt="Dot plot: destination of papers describing R packages in 2017" src="https://i1.wp.com/ropensci.org/img/blog-images/2018-03-20-rentrez-paper/journal_dot_plot.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>So, it looks like <em>Bioinformatics</em>, <em>BMC Bionformatics</em> and <em>Molecular Ecology<br>
Resources</em> are popular destinations for papers describing R packages, but these<br>
appear in journals all the way across the biological sciences.</p>
<p>The <em>R Journal</em> article describes some more typical uses of <code>rentrez</code>, and also<br>
describes some of decisions that went into the design of the package. If this<br>
example has whetted your appetite, then please check out the article or the<br>
<a rel="nofollow" href="https://cran.r-project.org/package=rentrez" target="_blank">package documentation</a>.</p>
<h2>Thanks</h2>
<p>The publication of this paper gives me a chance to thank the<br>
many people that have helped make <code>rentrez</code> into a useful package. I was very<br>
lucky to have this code included in rOpenSci at an early stage. Being part of<br>
the wider project made sure <code>rentrez</code> kept pace with the best-practices for code<br>
and documentation developed by the R community and got the package out to a wider<br>
audience than would have otherwise been possible. I am thankful to everyone who has<br>
filed an issue or contributed code to <code>rentrez</code>. I also have to<br>
single out Scott Chamberlain, who has done a great deal to make sure the code<br>
meets community standards and is useful to as many people as possible.</p>
<h2>API keys for eUtils</h2>
<p>To celebrate the publication of this paper I am going to speed up <code>rentrez</code> by a<br>
factor of three!</p>
<p>Well, the timing is coincidental, but the latest release of <code>rentrez</code> does make it<br>
possible to send and receive information from the NCBI at a greater rate than<br>
was previously possible. The NCBI now gives users the opportunity to <a rel="nofollow" href="https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/" target="_blank">register for an access<br>
key</a><br>
that will allow them to make up to 10 requests per second (non-registered users are limited<br>
to 3 requests per second per IP address). As of the latest release, <code>rentrez</code><br>
supports the use of these access keys while enforcing the appropriate rate limits.<br>
For one-off cases, this is as simple as adding the <code>api_key</code> argument to a given<br>
function call.</p>
<pre><code>prot_links &lt;- entrez_link(db=&quot;protein&quot;, dbfrom=&quot;gene&quot;, id=93100, api_key =&quot;ABCD123&quot;)
</code></pre>
<p>It most cases you will want to use your key for each of several calls to the<br>
NCBI. <code>rentrez</code> makes this easy by allowing you to set an environment variable,<br>
<code>ENTREZ_KEY</code>. Once this value is set to your key <code>rentrez</code> will use it for all<br>
requests to the NCBI. To set the value for a single R session you can use the<br>
function <code>set_entrez_key()</code>. Here we set the value and confirm it is now<br>
available as an environment variable.</p>
<pre><code>set_entrez_key(&quot;ABCD123&quot;)
Sys.getenv(&quot;ENTREZ_KEY&quot;)
</code></pre>
<pre><code>## [1] &quot;ABCD123&quot;
</code></pre>
<p>If you use <code>rentrez</code> often you should edit your <code>.Renviron</code> file (see<br>
<code>help(Startup)</code> for a description of this file) to include your key. Doing so will<br>
mean all requests you send will take advantage of your API key. Here’s the line<br>
to add:</p>
<pre><code>ENTREZ_KEY=ABCD123
</code></pre>
<p>As long as an API key is set by one of these methods, <code>rentrez</code> will allow you<br>
to make up to ten requests per second.</p>
<h2>Bugs and use-cases please!</h2>
<p>The publication in the <em>R Journal</em> is not the end of development for <code>rentrez</code>.<br>
Though the package is now feature-complete and stable, I am very keen to make sure<br>
it keeps pace with the API it wraps and squash any bugs that might arise. I also<br>
appreciate use-cases that demonstrate how the package can take advantage of NCBI<br>
data. So, please, <a rel="nofollow" href="https://github.com/ropensci/rentrez/issues" target="_blank">file issues at the project’s repository if you have any<br>
questions about it</a>!</p>
	<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/jStlGeNjuFI" height="1">