Luckily, you don't need to dive into serious customization
— the default (and currently only existing) style guide, tidyverse_style() has an indent_by parameter.
The part I found tricky:
There are 3 different equivalent ways of calling the top-level styling functions with your own values passed to tidyverse_style() parameters, which allows for shortcuts in some circumstances but I feel like is also a lot to wrap your head around. Adapted from the Customization vignette:
library(styler)
string_to_format <-
"mtcars %>%
dplyr::group_by(am, cyl) %>%
dplyr::summarise(
drat_mean = mean(drat),
disp_mean = mean(disp)
)"
all.equal(
style_text(string_to_format, transformers = tidyverse_style(indent_by = 4)),
style_text(string_to_format, style = tidyverse_style, indent_by = 4),
style_text(string_to_format, indent_by = 4),
)
#> [1] TRUE
style_text(string_to_format, style = tidyverse_style, indent_by = 4)
#> mtcars %>%
#> dplyr::group_by(am, cyl) %>%
#> dplyr::summarise(
#> drat_mean = mean(drat),
#> disp_mean = mean(disp)
#> )
Created on 2018-11-19 by the reprex package (v0.2.1)
The style parameter is basically just a shortcut that kicks off the construction of the transformers argument, so you can't do style = tidyverse_style(indent_by = 4).
Edited to add: I personally avoid the third syntax, because having that tidyverse_style() parameter sitting there looking like it's a style_text() parameter makes me itchy (I expect future-me-who-no-longer-remembers-how-it-all-works will not approve), but YMMV!