styler 1.1.0

[This article was first published on Lorenz Walthert, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

To leave a comment for the author, please follow the link and comment on their blog: Lorenz Walthert.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)