Learn R Programming

⚠️There's a newer version (1.11.0) of this package.Take me there.

styler

The goal of styler is to provide non-invasive pretty-printing of R source code while adhering to the tidyverse formatting rules. Support for custom style guides is planned.

You can install the package from GitHub:

# install.packages("remotes")
remotes::install_github("krlmlr/styler")

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

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

There are a few variants of style_text():

  • style_file() styles .R and/or .Rmd files.
  • style_dir() styles all .R 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 find more information on the wiki of Google Summer of Code 2017 or check out the pkgdown page.

Copy Link

Version

Install

install.packages('styler')

Monthly Downloads

58,138

Version

1.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Lorenz Walthert

Last Published

December 11th, 2017

Functions in styler (1.0.0)

reindention

Specify what is re-indented how
default_style_guide_attributes

Initialize default style guide attributes
create_style_guide

Create a style guide
math_token_spacing

Specify spacing around math tokens
style_file

Style .R and/or .Rmd files
style_text

Style a string
construct_vertical

Construct an object of class vertical
tidyverse_style

The tidyverse style
style_pkg

Prettify R source code
style_guides

Style guides
style_dir

Prettify arbitrary R code
styler-package

Non-invasive pretty printing of R code
styler_addins

Stylers for RStudio Addins