View source: R/poorly_styled_code.R
| poorly_styled_code | R Documentation |
Returns a long chunk of R/tidyverse code that has intentionally
inconsistent formatting, spacing, and indentation. It is designed for use in
demonstrations of code style tools such as styler::style_text() or
styler::style_file().
poorly_styled_code()
The code:
Loads dplyr, ggplot2, and stringr.
Performs grouping, summarisation, filtering, joining, and plotting on
the built-in mtcars dataset.
Is deliberately badly formatted (inconsistent spacing, misaligned pipes, poor indentation, inconsistent line breaks).
The output is meant to provide an example input for automatic code formatting tools, so that users can compare the before (poor style) and after (styled) versions. The code is only returned, never run.
A character vector of class psychdsish_code, with one element per line of
code. Printing it shows the code in the console; it can be passed directly
to styler::style_text() or written to a file with writeLines().
styler::style_text(), styler::style_file()
# Show the messy code
code <- poorly_styled_code()
code
# Pass it to styler to see how formatting improves
styler::style_text(code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.