styler 1.1.0

Nov 27, 2018 11:40 · 393 words · 2 minute read packages styler

This article was also published on r-bloggers.com

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

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

There were also quite a few minor changes, the most visible ones to the user were a complete re-design of the README and the fact that the cursor position is now remembered for styling via Addin. For details, you can have a look at the release notes or check the full 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 that the functionality of styler is also available in other packages:

  • usethis::use_tidy_style() styles your project according to the tidyverse style guide.
  • reprex::reprex(..., style = TRUE) to prettify reprex code before printing. To permanently use style = TRUE without specifying it every time, you can add the following line to your .Rprofile (via usethis::edit_r_profile()): options(reprex.styler = TRUE).
  • you can pretty-print your R code in RMarkdown reports without having styler modifying the source. This feature is implemented as a code chunk option in knitr. use tidy = "styler" in the header of a code chunks (e.g. ```{r name-of-the-chunk, tidy = "styler"}), or knitr::opts_chunk$set(tidy = "styler") at the top of your RMarkdown script. This feature requires the devel version of knitr.
  • pretty-printing of drake workflow data frames with drake::drake_plan_source().

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

tweet Share