<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/oneliner-a-new-style-guide-for-styler/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://lorenzwalthert.github.io/oneliner/"> Rsome - A blog about some R stuff</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I am happy to introduce <a rel="nofollow" href="https://github.com/lorenzwalthert/oneliner" target="_blank">oneliner</a>, a package that implements the <em>one-line-style</em> as a third-party style guide ready to use with <a rel="nofollow" href="https://github.com/r-lib/styler" target="_blank">styler</a>. Hence, after the tidyverse style guide, this is the first third-party style guide for styler I am aware of – and a particularly useful one.</p>
<p>Let’s see an example</p>
<figure>
<pre><code data-lang="r"><span># remotes::install_github(&quot;lorenzwalthert/oneliner&quot;)</span><span>
</span><span>library</span><span>(</span><span>oneliner</span><span>)</span><span>
</span><span>style_text</span><span>(</span><span>
</span><span>&quot;sum &lt;-function(x, y) {
x + # hi
y
}
1 + 1&quot;</span><span>,</span><span>
</span><span>style</span><span> </span><span>=</span><span> </span><span>one_line_style</span><span>
</span><span>)</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## sum &lt;- function(x,y){x+y};1+1</code></pre>
</figure>
<p>As you can guess from the name and the code above, the style guide has three rules only:</p>
<ul>
<li>Remove all comments.</li>
<li>Remove (almost all) spaces possible.</li>
<li>Put all code on one line.</li>
</ul>
<p>Compared to the <a rel="nofollow" href="http://style.tidyverse.org/" target="_blank">tidyverse style guide</a>, which contains 37 sections organized in seven chapters (with each section typically containing multiple rules), <em>one-line-style</em> is a great simplification to say the least. Further advantages of the style guide proposed include:</p>
<ul>
<li>Entirely self-explanatory (probably biggest plus).</li>
<li>It ends the tabs / spaces indention war in an unexpected and elegant<br>
way.</li>
<li>You don’t need to worry about EOL markers.</li>
<li>You can easily export to csv. One command per column.</li>
<li>People (including you) can’t read your code and think you are a genius.</li>
<li>and so on.</li>
</ul>
<p>I am sure I have convinced you that this style guide rocks. This is for<br>
real programmers. All code on one line. No spaces or comments. I am<br>
serious. Use this style guide to format your code like nerds do. Or if you quit a company and you want to give your team mates a little challenge.</p>
<p>As a final note, be aware that you can always use the tidyverse style guide on code that was styled according to <em>one-line-style</em> because the AST should not be changed with <em>one-line-style</em>.</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>&quot;styler&quot;</span><span>)</span><span>
</span><span>style_text</span><span>(</span><span>&quot;sum&lt;-function(x,y){x+y};1+1&quot;</span><span>,</span><span> </span><span>style</span><span> </span><span>=</span><span> </span><span>tidyverse_style</span><span>)</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## sum &lt;- function(x, y) {
##   x + y
## }
## 1 + 1</code></pre>
</figure>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://lorenzwalthert.github.io/oneliner/"> Rsome - A blog about some R stuff</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/AMllCbAzzj4" height="1"></a></div>