README.md

styler

Build
Status AppVeyor Build
Status lifecycle codecov cran
version

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:

Installation

You can install the package from CRAN.

install.packages("styler")

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")
remotes::install_github("r-lib/styler")

API

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

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

There are a few variants of style_text():

Configuration

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.

Features

Adaption of styler

styler functionality is made available through other tools, most notably

Further resources

Contributing

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

precommit::use_precommit()

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



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