stylerignore: Turn off styling for parts of the code

Description Details Examples

Description

Using stylerignore markers, you can temporarily turn off styler. Beware that for styler > 1.2.0, some alignment is detected by styler, making stylerignore redundant. See a few illustrative examples below.

Details

Styling is on by default when you run styler.

To use something else as start and stop markers, set the R options styler.ignore_start and styler.ignore_stop using options(). If you want these settings to persist over multiple R sessions, consider setting them in your R profile, e.g. with usethis::edit_rprofile().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# as long as the order of the markers is correct, the lines are ignored.
style_text(
  "
  1+1
  # styler: off
  1+1
  # styler: on
  1+1
  "
)

# if there is a stop marker before a start marker, styler won't be able
# to figure out which lines you want to ignore and won't ignore anything,
# issuing a warning.
## Not run: 
style_text(
  "
  1+1
  # styler: off
  1+1
  # styler: off
  1+1
  "
)

## End(Not run)
# some alignment of code is detected, so you don't need to use stylerignore
style_text(
  "call(
    xyz =  3,
    x   = 11
  )"
)

Example output

1 + 1
  # styler: off
  1+1
# styler: on
1 + 1

1 + 1
  # styler: off
  1+1
# styler: off
1 + 1
Warning messages:
1: Invalid stylerignore sequences found, potentially ignoring some of the markers set.
See `help("stylerignore", "styler")`. 
2: Invalid stylerignore sequences found, potentially ignoring some of the markers set.
See `help("stylerignore", "styler")`. 
call(
  xyz =  3,
  x   = 11
)

styler documentation built on Sept. 23, 2021, 5:07 p.m.