oneliner – a new style guide for styler

(This article was first published on Rsome - A blog about some R stuff, and kindly contributed to R-bloggers)

I am happy to introduce oneliner, a package that implements the one-line-style as a third-party style guide ready to use with styler. 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.

Let’s see an example

# remotes::install_github("lorenzwalthert/oneliner")
  "sum <- function(x, y) {
   x + # hi
  1 + 1",
  style = one_line_style
## sum <- function(x,y){x+y};1+1

As you can guess from the name and the code above, the style guide has three rules only:

  • Remove all comments.
  • Remove (almost all) spaces possible.
  • Put all code on one line.

Compared to the tidyverse style guide, which contains 37 sections organized in seven chapters (with each section typically containing multiple rules), one-line-style is a great simplification to say the least. Further advantages of the style guide proposed include:

  • Entirely self-explanatory (probably biggest plus).
  • It ends the tabs / spaces indention war in an unexpected and elegant
  • You don’t need to worry about EOL markers.
  • You can easily export to csv. One command per column.
  • People (including you) can’t read your code and think you are a genius.
  • and so on.

I am sure I have convinced you that this style guide rocks. This is for
real programmers. All code on one line. No spaces or comments. I am
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.

As a final note, be aware that you can always use the tidyverse style guide on code that was styled according to one-line-style because the AST should not be changed with one-line-style.

style_text("sum<-function(x,y){x+y};1+1", style = tidyverse_style)
## sum <- function(x, y) {
##   x + y
## }
## 1 + 1

To leave a comment for the author, please follow the link and comment on their blog: Rsome - A blog about some R stuff. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)