Skip to content

Commit 019c0f9

Browse files
Merge pull request #232 from lorenzwalthert/improve_vignettes
Improve vignettes (#232).
2 parents 475a391 + ef7162c commit 019c0f9

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

vignettes/customizing_styler.Rmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ There are three major steps that styler performs in order to style code:
2323
2. Apply transformer functions at each level of the nested parse table. We use a
2424
visitor approach, i.e. a function that takes functions as arguments and
2525
applies them to every level of nesting. You can find out more about it on
26-
the help file for `visit`. Note that the function is not exported by styler.
26+
the help file for `visit()`. Note that the function is not exported by styler.
2727
The visitor will take care of applying the functions on every
2828
level of nesting - and we can supply transformer functions that operate on
2929
one level of nesting. In the sequel, we use the term *nest* to refer to
@@ -52,7 +52,7 @@ names(tidyverse_style())
5252
str(tidyverse_style(), give.attr = FALSE, list.len = 3)
5353
```
5454

55-
We note that there are different types of transformer functions. `filler`
55+
We note that there are different types of transformer functions. `initialize`
5656
initializes some variables in the nested parse table (so it is not actually a
5757
transformer), and the other elements modify either spacing, line breaks or
5858
tokens. `use_raw_indention` is not a function, it is just an option. All
@@ -286,3 +286,5 @@ removes line breaks before the curly opening bracket looks as follows:
286286
styler:::remove_line_break_before_curly_opening
287287
```
288288

289+
With our example function `set_line_break_before_curly_opening()` we don't need
290+
to worry about that as we are only adding line breaks, but we don't remove them.

vignettes/introducing_styler.Rmd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ more examples of code before and after styling.
121121
1++1-1-1/2
122122
```
123123

124+
This is tidyverse style. However, styler offers very granular control for
125+
math token spacing. Assuming you like spacing around `+` and `-`, but not
126+
around `/` and `*` and `^`, do the following:
127+
```{r}
128+
style_text(
129+
"1++1/2*2^2",
130+
math_token_spacing = specify_math_token_spacing(zero = c("'/'", "'*'", "'^'"))
131+
)
132+
```
133+
124134
It can also format complicated expressions that involve line breaking and
125135
indention based on both brace expressions and operators:
126136

@@ -176,3 +186,20 @@ z) {
176186
mtcars %>%
177187
group_by( !!my_vars )
178188
```
189+
190+
If you, say, don't want comments starting with `###` to be indented, you can
191+
formulate an unindention rule:
192+
```{r}
193+
style_text(
194+
c(
195+
"a <- function() {",
196+
"### not to be indented",
197+
"# indent normally",
198+
"33",
199+
"}"
200+
),
201+
reindention = specify_reindention(regex_pattern = "###", indention = 0)
202+
203+
)
204+
```
205+

0 commit comments

Comments
 (0)