styler 1.1.0

styler 1.1.0 is now available on CRAN. Thisrelease introduces new features and is fully backward-compatible. It alsoadapts to changes in the R parser committed into R devel (#419). Major changesare:

  • styler can now style roxygen code examples in the source code of package.This might be helpful for package developers. The option is enabled bydefault, so you have to explicitly turn it off if you want styler to leavethe code examples as is:
1
styler::style_pkg(include_roxygen_examples = FALSE)
  • In addition to R and Rmd files, styler can now handle Rnw files too. The APIignores capitalization and dot-prefixing for file types:
1
styler::style_dir(filetype = c("r", "Rmd", ".rnw"))
  • the print method for the output of style_text() (print.vertical()) nowreturns syntax-highlighted code by default, controllable via the optionstyler.colored_print.vertical using the prettycode package. This onlyworks when ran in a console though, so you can c/p this snippet into yoursto see how it works:
1
2
3
4
5
styler::style_text(c(
 "add <- function(...) {", 
 "purrr::reduce(list(...), `+`)", 
 "}"
))

There were also quite a few minor changes, the most visible ones to the userwere a complete re-design of the README and the fact that the cursor position isnow remembered for styling via Addin. For details, you can have a look at the release notes or check thefull commit history.

Thanks to all contributors for patches, issues and the like:@jonmcalder, @krlmlr, @IndrajeetPatil, @kalibera, @Hasnep, @kiranmaiganji,@dirkschumacher, @ClaytonJY, @wlandau, @maurolepore.

Although not directly related to this release, we would like to highlight thatthe functionality of styler is also available in other packages:

  • usethis::use_tidy_style() styles your project according to thetidyverse style guide.

  • reprex::reprex(..., style = TRUE) to prettify reprex code beforeprinting. To permanently use style = TRUE without specifying itevery time, you can add the following line to your .Rprofile (viausethis::edit_r_profile()): options(reprex.styler = TRUE).

  • you can pretty-print your R code in RMarkdown reports without havingstyler modifying the source. This feature is implemented as a codechunk option in knitr. use tidy = "styler" in the header of a codechunks (e.g. ````{r name-of-the-chunk, tidy = “styler”}), orknitr::opts_chunk$set(tidy = “styler”)` at the top of yourRMarkdown script. This feature requires the devel version of knitr.

  • pretty-printing of drakeworkflow data frames with drake::drake_plan_source().

For a complete walk-through we recommend to have a look at the initial blog post that introducesstyler.

Related