grk_style | R Documentation |
Use styler::style_text()
to format code according to the unofficial
grkstyle style guide. Follows the
tidyverse style guide as implemented by
styler::tidyverse_style()
, but with additional style rules that enforce
consistent line breaks inside function calls and left-justification of
function arguments in function definitions.
use_grk_style()
grk_style_transformer(..., use_tabs = getOption("grkstyle.use_tabs", NULL))
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 |
use_tabs |
Should a single tab be used for indentation? grkstyle
functions will by default follow the If not otherwise set via the R option or the RStudio project option, tabs are used. Tabs are recommended because they are more accessible. You can opt into indentation by two spaces by setting the
# two spaces options(grkstyle.use_tabs = FALSE) # equivalently, but more precise options(grkstyle.use_tabs = list(indent_by = 2, indent_character = " ")) |
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 grkstyle 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 grkstyle code style
grk_style_file
: Style a file using the grkstyle code style
grk_style_dir
: Style a directory using the grkstyle code style
grk_style_pkg
: Style a package using the grkstyle code style
You can set the grkstyle
code style as the default code style for styler (and its associated
RStudio addins, like "Style active file" and "Style selection") by calling
grkstyle::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 = "grkstyle::grk_style_transformer()")
## Not run:
use_grk_style()
# Use styler addins
styler:::style_selection()
## End(Not run)
ex_code <- "mtcars %>% mutate(mpg = mpg * 2,\n\t\t cyl = paste(cyl)) %>% head()"
cat(ex_code)
grk_style_text(ex_code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.