Status AppVeyor Build
Status lifecycle codecov cran

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.

The following online docs are available:


You can install the package from CRAN.


If you don’t use styler interactively (i.e. not from the R prompt or RStudio Addin), make sure you authorize {R.cache} once to set up a permanent cache. If you use it interactively, you will be asked to grant this permission once. See ?caching for details.

Or get the development version from GitHub:

# install.packages("remotes")


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

ugly_code <- "a=function( x){1+1}           "
#> a <- function(x) {
#>   1 + 1
#> }

There are a few variants of style_text():


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

ugly_code <- "a=function( x){1+1}           "
style_text(ugly_code, scope = "spaces")
#> a = function(x) {1 + 1}

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

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

This was just the tip of the iceberg. To learn more about customization options with the tidyverse style guide, see the help file for `tidyverse_style for a quick overview or the introductory vignette.


Adaption of styler

styler functionality is made available through other tools, most notably

Further resources


Please have a look at, in particular, make sure to use the pre-commit hooks and if you skip a hook, describe why in the PR. See the {precommit} on how to install the pre-commit framework and the R package on your system and then run


to make sure the hooks are activated in your local styler clone.

krlmlr/styler documentation built on Oct. 25, 2020, 8:13 a.m.