diff --git a/DESCRIPTION b/DESCRIPTION index 6af47123..8a0fad6d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: BiocCheck -Version: 1.25.0 +Version: 1.25.1 Title: Bioconductor-specific package checks Description: Executes Bioconductor-specific package checks. Authors@R: c( diff --git a/NEWS b/NEWS index 903e54eb..4b5659a0 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +CHANGES IN VERSION 1.25 +----------------------- + +USER SIGNIFICANT CHANGES + + o (1.25.1) Suggest styler over formatR for automatic code re-formatting. + CHANGES IN VERSION 1.23 ----------------------- @@ -98,4 +105,4 @@ NEW FEATURES BUG FIXES - o Use shell quotes to allow spaces in package paths \ No newline at end of file + o Use shell quotes to allow spaces in package paths diff --git a/R/checks.R b/R/checks.R index 689256e3..89d8db57 100644 --- a/R/checks.R +++ b/R/checks.R @@ -1431,7 +1431,11 @@ checkFormatting <- function(pkgdir, nlines=6) handleMessage( "See http://bioconductor.org/developers/how-to/coding-style/") handleMessage( - "See FormatR package: https://cran.r-project.org/web/packages/formatR/index.html") + "See styler package: https://styler.r-lib.org/ ", + "as described in the BiocCheck vignette.") + handleMessage( + "See also biocthis: ", + "https://lcolladotor.github.io/biocthis/reference/bioc_style.html") } } diff --git a/vignettes/BiocCheck.Rmd b/vignettes/BiocCheck.Rmd index fcd8750a..e315e4e7 100644 --- a/vignettes/BiocCheck.Rmd +++ b/vignettes/BiocCheck.Rmd @@ -550,10 +550,48 @@ The output of this check includes the first 6 offending lines of code; see more with `BiocCheck:::checkFormatting("path/to/YourPackage", nlines=Inf)`. -There is a helpful package [formatR][formatR] that can be used for formatting of -R code to particular coding standards. +There are several helpful packages that can be used for formatting of +R code to particular coding standards such as [formatR][formatR] and +[styler][styler] as well as the "Reformat code" button in +[RStudio Desktop][RStudio]. Each solution has its advantages, though +[styler][styler] works with `roxygen2` examples and is actively +maintained. You can re-format your code using [styler][styler] as shown +below: + +```{r reformat_code, eval = FALSE} +## Install styler if necessary +if (!requireNamespace("styler", quietly = TRUE)) { + install.packages("styler") +} +## Automatically re-format the R code in your package +styler::style_pkg(transformers = styler::tidyverse_style(indent_by = 4)) + +## If using biocthis: +styler::style_pkg(transformers = biocthis::bioc_style()) + +## For your Rmd vignette files: +styler::style_dir( + "vignettes", + transformers = biocthis::bioc_style(), + filetype = "Rmd" +) +``` + +You can also use [`biocthis::bioc_style()`][biocstyle] which adapts the +`tidverse_style()` to make it more Bioconductor-friendly. If you are +working with [RStudio Desktop][RStudio] use also the "Reformat code" +button which will help you break long lines of code. Alternatively, +use [formatR][formatR], though beware that it can break valid code +involving both type of quotation marks (`"` and `'`) and does not +support re-formatting `roxygen2` examples. In general, +it is best to version control your code before applying any +automatic re-formatting solutions and implement unit tests to +verify that your code runs as intended after you re-format your code. [formatR]: https://cran.r-project.org/web/packages/formatR/index.html +[styler]: https://styler.r-lib.org/ +[RStudio]: https://rstudio.com/products/rstudio/download/ +[biocstyle]: https://lcolladotor.github.io/biocthis/reference/bioc_style.html ## Duplication checks