kpj / blackstyle

Black for R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

blackstyle

blackstyle is an extension package for styler that holds my personal code style preferences.

Installation

You can install the blackstyle from Github

# install.packages("remotes")
remotes::install_github("kpj/blackstyle")

Usage

To use blackstyle by default in styler functions and addins

# Set default code style for {styler} functions
blackstyle::use_black_style()

Or add the following to your ~/.Rprofile

options(styler.addins_style_transformer = "blackstyle::black_style_transformer()")

Examples

A few examples drawn from the tidyverse style guide.

Line Breaks Inside Function Calls

unstyled

do_something_very_complicated(something = "that", requires = many,
                              arguments = "some of which may be long")

blackstyle

do_something_very_complicated(
  something = "that",
  requires = many,
  arguments = "some of which may be long"
) 

styler::tidyverse_style

do_something_very_complicated(
  something = "that", requires = many,
  arguments = "some of which may be long"
) 

Indentation of Function Arguments

unstyled

long_function_name <- function(a = "a long argument",
                               b = "another argument",
                               c = "another long argument") {
  # As usual code is indented by two spaces.
}

blackstyle

long_function_name <- function(
  a = "a long argument",
  b = "another argument",
  c = "another long argument"
) {
  # As usual code is indented by two spaces.
} 

styler::tidyverse_style

long_function_name <- function(a = "a long argument",
                               b = "another argument",
                               c = "another long argument") {
  # As usual code is indented by two spaces.
} 

About

Black for R

License:MIT License


Languages

Language:R 100.0%