Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

style_roxygen_code_example_segment

Style a roxygen code example segment


Description

A roxygen code example segment corresponds to roxygen example code that contains at most one \\dontrun{...} or friends. We drop all newline characters first because otherwise the code segment passed to this function was previously parsed with parse_roxygen() and line-breaks in and after the \\dontrun{...} are expressed with "\n", which contradicts to the definition used elsewhere in this package, where every element in a vector corresponds to a line. These line-breaks don't get eliminated because they move to the front of a code_segment and style_text("\n1") gives "\n1", i.e. trailing newlines are not eliminated.

Usage

style_roxygen_code_example_segment(one_dont, transformers, base_indention)

Arguments

one_dont

Bare R code containing at most one \\dontrun{...} or friends.

transformers

Passed to cache_make_key() to generate a key.

base_indention

Integer scalar indicating by how many spaces the whole output text should be indented. Note that this is not the same as splitting by line and add a base_indention spaces before the code in the case multi-line strings are present. See 'Examples'.

Hierarchy

Styling involves splitting roxygen example code into segments, and segments into snippets. This describes the process for input of parse_transform_serialize_roxygen():

  • Splitting code into roxygen example code and other code. Downstream, we are only concerned about roxygen code. See parse_transform_serialize_roxygen().

  • Every roxygen example code can have zero or more dontrun / dontshow / donttest sequences. We next create segments of roxygen code examples that contain at most one of these. See style_roxygen_code_example().

  • We further split the segment that contains at most one dont* sequence into snippets that are either don* or not. See style_roxygen_code_example_segment().

Finally, that we have roxygen code snippets that are either dont* or not, we style them in style_roxygen_example_snippet() using parse_transform_serialize_r().


styler

Non-Invasive Pretty Printing of R Code

v1.4.1
MIT + file LICENSE
Authors
Kirill Müller [aut], Lorenz Walthert [cre, aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.