styler 1.1.0

October 20, 2018
By

(This article was first published on Lorenz Walthert, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

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)