The goal of styler is to provide non-invasive pretty-printing of R source code while adhering to the tidyverse formatting rules. styler can be customized to format code according to other style guides too.


You can install the package from CRAN:

Or get the development version from GitHub:


You can style a simple character vector of code with style_text():

There are a few variants of style_text():

  • style_file() styles .R and/or .Rmd files.

  • style_dir() styles all .R and/or .Rmd files in a directory.

  • style_pkg() styles the source files of an R package.

  • RStudio Addins for styling the active file, styling the current package and styling the highlighted code region.



You can decide on the level of invasiveness with the scope argument. You can style:

  • just spaces.

  • spaces and indention.

  • spaces, indention and line breaks.

  • spaces, indention, line breaks and tokens.

Note that compared to the default used above scope = "tokens":

  • no line breaks were added.

  • <- was not replaced with =.

While spaces still got styled (around = in (x)).


If you wish to keep alignment as is, you can use strict = FALSE:

This was just the tip of the iceberg. Learn more about customization with the tidyverse style guide in in this vignette. If this is not flexible enough for you, you can implement your own style guide, as explained in the corresponding vignette.

Adaption of styler

styler functionality is made available through other tools, most notably

Further resources

  • The official web documentation of styler, containing various vignettes function documentation as well as a change-log.

  • Blog post about how you can customize styler without being an expert.

  • A blog post introducing the functionality of styler and a follow-up post that introduces the new features since release 1.0.0.

  • The wiki of Google Summer of Code 2017 or the pkgdown page contain information related to the initial development phase during Google Summer of Code 2017.