Use styler::style_text()
to format code according to the unofficial
grkmisc style guide.
use_grk_style() grk_style_transformer(...) grk_style_text(text, ...) grk_style_file(path, ...) grk_style_dir(path, ...) grk_style_pkg(pkg, ...)
... | Arguments passed to underling styler functions (identified
by removing the |
---|---|
text | A character vector with text to style. |
path | A character vector with paths to files to style. |
pkg | Path to a (subdirectory of an) R package. |
use_grk_style
: Set the grkmisc style as the default style for
styler addins.
grk_style_transformer
: A code transformer for use with styler::style_text()
grk_style_text
: Style text using the grkmisc code style
grk_style_file
: Style a file using the grkmisc code style
grk_style_dir
: Style a directory using the grkmisc code style
grk_style_pkg
: Style a package using the grkmisc code style
You can set the grkmisc code
style as the default code style for styler (and its associated
RStudio addins, like "Style active file" and "Style selection") by calling
grkmisc::use_grk_style()
. If you would rather set this option globally
for all session, you can add the following to your .Rprofile
:
options(styler.addins_style_transformer = "grkmisc::grk_style_transformer()")
if (FALSE) { use_grk_style() # Use styler addins styler:::style_selection() } ex_code <- "mtcars %>% mutate(mpg = mpg * 2,\n\t\t cyl = paste(cyl)) %>% head()" cat(ex_code)#> mtcars %>% mutate(mpg = mpg * 2, #> cyl = paste(cyl)) %>% head()grk_style_text(ex_code)#> Warning: Could not use colored = TRUE, as the package prettycode is not installed. Please install it if you want to see colored output or see `?print.vertical` for more information.#> mtcars %>% #> mutate( #> mpg = mpg * 2, #> cyl = paste(cyl) #> ) %>% #> head()