Yes, it's totally possible with styler. If you want to apply the spacing rules (which includes indention) of the tidyverse style guide, you can simply
library(styler)
style_text(c(
"a = 3",
"function(x) {",
"3+1",
"}"
), transformers = style_guide)
#> a = 3
#> function(x) {
#> 3 + 1
#> }
or
styler::style_dir(scope = "indention")
To style a directory. If you want just the indention rules, you can also remove all non-indention spacing transformers from the style guide after you created it:
library(styler)
style_guide <- tidyverse_style(scope = "indention")
# indention rules are sub-domain of spaces. Just keep all spacing rules which
# name contains "indent" and discard all other.
indention_rules <- grep("indent", names(style_guide$space), value = TRUE)
style_guide$space <- style_guide$space[indention_rules]
style_text(c(
"a = 3",
"function(x) {",
"3+1",
"}"
), transformers = style_guide)
#> a = 3
#> function(x) {
#> 3+1
#> }
If you want to indent by - say 4 spaces, you can also do that when you create the style guide like this:
style_guide <- tidyverse_style(scope = "indention", indent_by = 4)