<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/probably-the-most-useful-r-function-ive-ever-written/"></div></div><div><a data-url="https://www.r-bloggers.com/probably-the-most-useful-r-function-ive-ever-written/" data-counturl="https://www.r-bloggers.com/probably-the-most-useful-r-function-ive-ever-written/" data-count="horizontal" data-text="Probably the most useful R function I’ve ever written" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.burns-stat.com/probably-useful-r-function-ive-ever-written/"> R language – Burns Statistics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The function in question is <code>scriptSearch</code>. I’m not much for superlatives — “most” and “best” imply one dimension, but we live in a multi-dimensional world. I’m making an exception.</p>
<p>The statistic I have in mind for this use of “useful” is the waiting time between calls to the function divided by the human time saved by the call.</p>
<p>I wrote a version of this for a company where I do consulting. There are few days working there that I don’t have at least one bout with it.  Using <code>scriptSearch</code> can easily save half an hour compared to what I would have done prior to having the function.</p>
<p><span></span></p>
<h2>scriptSearch</h2>
<p>The two main inputs are:</p>
<ul>
<li>a string to search for</li>
<li>a directory to search in</li>
</ul>
<p>By default it only looks in R scripts in the directory (and its subdirectories).</p>
<p>Examples of directories to search are:</p>
<ul>
<li>directory holding a large collection of R scripts</li>
<li>directory holding the source for local R packages</li>
<li>personal directory with lots of subdirectories containing R scripts and functions</li>
</ul>
<p>Examples of uses are:</p>
<ul>
<li>where is <code>blimblam</code> defined?</li>
<li>where are all the uses of <code>splishsplash</code> in the local packages (because I want to change its arguments)?</li>
<li>a few weeks ago I created a pdf called <code>factor_history</code>, where is the code that produced that?</li>
</ul>
<p>These uses might be done with something like:</p>
<ul>
<li><code>scriptSearch(&quot;blimblam *&lt;-&quot;, &quot;path/to/scriptFarm&quot;, sub=FALSE)</code></li>
<li><code>scriptSearch(&quot;splishsplash&quot;, &quot;path/to/Rsource&quot;)</code></li>
<li><code>scriptSearch(&quot;factor_history&quot;, &quot;..&quot;)</code></li>
</ul>
<p>You may be confused by the asterisk in the first call.  The string to search for can be a regular expression.  In this case the asterisk means that it will find assignments whether or not there is a space between the object name and the assignment arrow.</p>
<h2>BurStMisc</h2>
<p><code>scriptSearch</code> was the main motivation for updating the BurStMisc package to version 1.1.  The package is on CRAN.</p>
<h2>ntile</h2>
<p>The <code>ntile</code> function is also new to BurStMisc.  It returns equally-sized ordered groups from a numeric vector — for example, quintiles or deciles.</p>
<p>A more primitive version of the function appeared in a blog post called <a target="_blank" href="http://www.portfolioprobe.com/2012/12/24/miles-of-iles/">“Miles of iles”</a>.  There is some discussion there of alternative functions.</p>
<h2>writeExpectTest</h2>
<p>While I was preparing the update to BurStMisc, I found that automating the writing of some tests using the <code>testthat</code> package was both warranted and feasible.  The <code>writeExpectTest</code> function is the result.</p>
<h2>corner</h2>
<p>The generally useful function that was already in BurStMisc is <code>corner</code>.  This allows you to see a few rows and columns of a large matrix or data frame — or higher dimensional array.</p>
<h2>Epilogue</h2>
<p><em>I want to spread the news</em><br>
<em>That if it feels this good getting used</em><br>
<em>You just keep on using me</em></p>
<p>— from “Use Me”  by Bill Withers<br>
<iframe height="315" width="420" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/NcFaVfTDWcs"></iframe></p>
<p>The post <a target="_blank" rel="nofollow" href="http://www.burns-stat.com/probably-useful-r-function-ive-ever-written/">Probably the most useful R function I’ve ever written</a> appeared first on <a target="_blank" rel="nofollow" href="http://www.burns-stat.com/">Burns Statistics</a>.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/probably-the-most-useful-r-function-ive-ever-written/"></div></div><div><a data-url="https://www.r-bloggers.com/probably-the-most-useful-r-function-ive-ever-written/" data-counturl="https://www.r-bloggers.com/probably-the-most-useful-r-function-ive-ever-written/" data-count="vertical" data-text="Probably the most useful R function I’ve ever written" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.burns-stat.com/probably-useful-r-function-ive-ever-written/"> R language – Burns Statistics</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/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=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/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/MMXFIhEl8A4"></a></div>