Skip to content

Commit 5604071

Browse files
committed
v1.25.1 -- Resolve #57
This commit resolves #57 by updating the `handleMessage()` calls after the formatting check fails. Instead of mentioning `formatR`, these messages now refer to: * `styler`, * `biocthis`, * the `BiocCheck` vignette. Furthermore, the `BiocCheck` vignette section on formatting still mentions `formatR`, but it now also mentions in more detail: * `styler`: how to install and run it * `biocthis`: as a companion to `styler` with code how to run it (but not install it since it's optional and the install instructions will hopefully change soon once this package is submitted/reviewed). * a quick overview of the differences between `formatR` and `styler`, though this is mostly done by highlighting current limitations of `formatR`. * how RStudio Desktop's `Reformat code` button (under the magic wand) can help break long lines which is something that `styler` cannot do as discussed in more detail at r-lib/styler#247. `formatR` can do this, but personally, the fact that it broke valid R code in some of my packages made me trust its output less. The NEWS and DESCRIPTION files have been updated accordingly.
1 parent 4687a90 commit 5604071

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: BiocCheck
2-
Version: 1.25.0
2+
Version: 1.25.1
33
Title: Bioconductor-specific package checks
44
Description: Executes Bioconductor-specific package checks.
55
Authors@R: c(

NEWS

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
CHANGES IN VERSION 1.25
2+
-----------------------
3+
4+
USER SIGNIFICANT CHANGES
5+
6+
o (1.25.1) Suggest styler over formatR for automatic code re-formatting.
7+
18
CHANGES IN VERSION 1.23
29
-----------------------
310

@@ -98,4 +105,4 @@ NEW FEATURES
98105

99106
BUG FIXES
100107

101-
o Use shell quotes to allow spaces in package paths
108+
o Use shell quotes to allow spaces in package paths

R/checks.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,11 @@ checkFormatting <- function(pkgdir, nlines=6)
14311431
handleMessage(
14321432
"See http://bioconductor.org/developers/how-to/coding-style/")
14331433
handleMessage(
1434-
"See FormatR package: https://cran.r-project.org/web/packages/formatR/index.html")
1434+
"See styler package: https://styler.r-lib.org/ ",
1435+
"as described in the BiocCheck vignette.")
1436+
handleMessage(
1437+
"See also biocthis: ",
1438+
"https://lcolladotor.github.io/biocthis/reference/bioc_style.html")
14351439
}
14361440
}
14371441

vignettes/BiocCheck.Rmd

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,48 @@ The output of this check includes the first 6 offending lines of code;
550550
see more with `BiocCheck:::checkFormatting("path/to/YourPackage",
551551
nlines=Inf)`.
552552

553-
There is a helpful package [formatR][formatR] that can be used for formatting of
554-
R code to particular coding standards.
553+
There are several helpful packages that can be used for formatting of
554+
R code to particular coding standards such as [formatR][formatR] and
555+
[styler][styler] as well as the "Reformat code" button in
556+
[RStudio Desktop][RStudio]. Each solution has its advantages, though
557+
[styler][styler] works with `roxygen2` examples and is actively
558+
maintained. You can re-format your code using [styler][styler] as shown
559+
below:
560+
561+
```{r reformat_code, eval = FALSE}
562+
## Install styler if necessary
563+
if (!requireNamespace("styler", quietly = TRUE)) {
564+
install.packages("styler")
565+
}
566+
## Automatically re-format the R code in your package
567+
styler::style_pkg(transformers = styler::tidyverse_style(indent_by = 4))
568+
569+
## If using biocthis:
570+
styler::style_pkg(transformers = biocthis::bioc_style())
571+
572+
## For your Rmd vignette files:
573+
styler::style_dir(
574+
"vignettes",
575+
transformers = biocthis::bioc_style(),
576+
filetype = "Rmd"
577+
)
578+
```
579+
580+
You can also use [`biocthis::bioc_style()`][biocstyle] which adapts the
581+
`tidverse_style()` to make it more Bioconductor-friendly. If you are
582+
working with [RStudio Desktop][RStudio] use also the "Reformat code"
583+
button which will help you break long lines of code. Alternatively,
584+
use [formatR][formatR], though beware that it can break valid code
585+
involving both type of quotation marks (`"` and `'`) and does not
586+
support re-formatting `roxygen2` examples. In general,
587+
it is best to version control your code before applying any
588+
automatic re-formatting solutions and implement unit tests to
589+
verify that your code runs as intended after you re-format your code.
555590

556591
[formatR]: https://cran.r-project.org/web/packages/formatR/index.html
592+
[styler]: https://styler.r-lib.org/
593+
[RStudio]: https://rstudio.com/products/rstudio/download/
594+
[biocstyle]: https://lcolladotor.github.io/biocthis/reference/bioc_style.html
557595

558596
## Duplication checks
559597

0 commit comments

Comments
 (0)