Skip to content

Commit ee8eb81

Browse files
Merge pull request #1068 from r-lib/check_examples
Check if all examples run successfully
2 parents 55e8559 + 467d2f4 commit ee8eb81

12 files changed

+165
-133
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Make sure all examples run successfully, even the ones that are not supposed
2+
# to be run or tested on CRAN machines by default.
3+
#
4+
# The examples that fail should use
5+
# - `if (FALSE) { ... }` (if example is included only for illustrative purposes)
6+
# - `try({ ... })` (if the intent is to show the error)
7+
#
8+
# This workflow helps find such failing examples that need to be modified.
9+
10+
on:
11+
push:
12+
branches: [main, master]
13+
pull_request:
14+
branches: [main, master]
15+
16+
name: check-all-examples
17+
18+
jobs:
19+
check-all-examples:
20+
runs-on: ubuntu-latest
21+
env:
22+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- uses: r-lib/actions/setup-r@v2
28+
with:
29+
use-public-rspm: true
30+
31+
- uses: r-lib/actions/setup-r-dependencies@v2
32+
with:
33+
pak-version: devel
34+
extra-packages: |
35+
any::devtools
36+
local::.
37+
38+
- name: Run examples
39+
run: |
40+
options(crayon.enabled = TRUE)
41+
devtools::run_examples(fresh = TRUE, run_dontrun = TRUE, run_donttest = TRUE)
42+
shell: Rscript {0}

R/parse.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
#' @param ... Parameters passed to [base::parse()].
99
#' @keywords internal
1010
#' @examples
11-
#' \dontrun{
12-
#' styler:::parse_safely("a + 3 -4 -> x\r\n glück + 1")
11+
#' try(styler:::parse_safely("a + 3 -4 -> x\r\n glück + 1"))
1312
#' # This cannot be detected as a EOL style problem because the first
1413
#' # line ends as expected with \n
15-
#' styler:::parse_safely("a + 3 -4 -> x\nx + 2\r\n glück + 1")
16-
#' }
14+
#' try(styler:::parse_safely("a + 3 -4 -> x\nx + 2\r\n glück + 1"))
15+
#'
1716
#' styler:::parse_safely("a + 3 -4 -> \n glück + 1")
1817
parse_safely <- function(text, ...) {
1918
tried_parsing <- rlang::with_handlers(

R/rules-line-breaks.R

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,48 @@
1010
#' line trigger.
1111
#' @keywords internal
1212
#' @examples
13-
#' \dontrun{
14-
#' tryCatch(
15-
#' {
16-
#' f(8)
17-
#' },
18-
#' error = function(e) NULL
19-
#' )
20-
#' # last-argument case
21-
#' testthat("braces braces are cool", {
22-
#' code(to = execute)
23-
#' })
24-
#' call2(
25-
#' x = 2, {
13+
#' if (FALSE) {
14+
#' tryCatch(
15+
#' {
16+
#' f(8)
17+
#' },
18+
#' error = function(e) NULL
19+
#' )
20+
#' # last-argument case
21+
#' testthat("braces braces are cool", {
2622
#' code(to = execute)
27-
#' },
28-
#' c = {
29-
#' # this is the named case
30-
#' g(x = 7)
31-
#' }
32-
#' )
33-
#' tryGugus(
34-
#' {
35-
#' g5(k = na)
36-
#' },
37-
#' a + b # line break also here because
38-
#' # preceded by brace expression
39-
#' )
23+
#' })
24+
#' call2(
25+
#' x = 2, {
26+
#' code(to = execute)
27+
#' },
28+
#' c = {
29+
#' # this is the named case
30+
#' g(x = 7)
31+
#' }
32+
#' )
33+
#' tryGugus(
34+
#' {
35+
#' g5(k = na)
36+
#' },
37+
#' a + b # line break also here because
38+
#' # preceded by brace expression
39+
#' )
4040
#'
41-
#' # brace expressions go on new line if part of a pipe, in function call...
42-
#' c(
41+
#' # brace expressions go on new line if part of a pipe, in function call...
42+
#' c(
43+
#' data %>%
44+
#' filter(bar) %>%
45+
#' {
46+
#' cor(.$col1, .$col2, use = "complete.obs")
47+
#' }
48+
#' )
49+
#' # ... or outside
4350
#' data %>%
4451
#' filter(bar) %>%
4552
#' {
4653
#' cor(.$col1, .$col2, use = "complete.obs")
4754
#' }
48-
#' )
49-
#' # ... or outside
50-
#' data %>%
51-
#' filter(bar) %>%
52-
#' {
53-
#' cor(.$col1, .$col2, use = "complete.obs")
54-
#' }
5555
#' }
5656
set_line_break_before_curly_opening <- function(pd) {
5757
line_break_to_set_idx <- which(

R/set-assert-args.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ assert_transformers <- function(transformers) {
5656
#' standard format.
5757
#' @examples
5858
#' styler:::set_and_assert_arg_filetype("rMd")
59-
#' \dontrun{
60-
#' styler:::set_and_assert_arg_filetype("xyz")
61-
#' }
59+
#' try(styler:::set_and_assert_arg_filetype("xyz"))
6260
#' @keywords internal
6361
set_and_assert_arg_filetype <- function(filetype) {
6462
without_dot <- gsub("^\\.", "", tolower(filetype))

R/transform-files.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ parse_tree_must_be_identical <- function(transformers) {
397397
#' @examples
398398
#' styler:::verify_roundtrip("a+1", "a + 1")
399399
#' styler:::verify_roundtrip("a+1", "a + 1 # comments are dropped")
400-
#' \dontrun{
401-
#' styler:::verify_roundtrip("a+1", "b - 3")
402-
#' }
400+
#' try(styler:::verify_roundtrip("a+1", "b - 3"))
403401
#' @keywords internal
404402
verify_roundtrip <- function(old_text, new_text, parsable_only = FALSE) {
405403
if (parsable_only) {

R/ui-styling.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@
4949
#' @inheritSection transform_files Value
5050
#' @family stylers
5151
#' @examples
52-
#' \dontrun{
53-
#' # the following is identical (because of ... and defaults)
54-
#' # but the first is most convenient:
55-
#' style_pkg(strict = TRUE)
56-
#' style_pkg(style = tidyverse_style, strict = TRUE)
57-
#' style_pkg(transformers = tidyverse_style(strict = TRUE))
52+
#' if (FALSE) {
53+
#' # the following is identical (because of ... and defaults)
54+
#' # but the first is most convenient:
55+
#' style_pkg(strict = TRUE)
56+
#' style_pkg(style = tidyverse_style, strict = TRUE)
57+
#' style_pkg(transformers = tidyverse_style(strict = TRUE))
5858
#'
59-
#' # more options from `tidyverse_style()`
60-
#' style_pkg(
61-
#' scope = "line_breaks",
62-
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
63-
#' )
59+
#' # more options from `tidyverse_style()`
60+
#' style_pkg(
61+
#' scope = "line_breaks",
62+
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
63+
#' )
6464
#'
65-
#' # don't write back and fail if input is not already styled
66-
#' style_pkg("/path/to/pkg/", dry = "fail")
65+
#' # don't write back and fail if input is not already styled
66+
#' style_pkg("/path/to/pkg/", dry = "fail")
6767
#' }
6868
#' @export
6969
style_pkg <- function(pkg = ".",
@@ -236,14 +236,14 @@ style_text <- function(text,
236236
#' @inheritSection style_pkg Round trip validation
237237
#' @family stylers
238238
#' @examples
239-
#' \dontrun{
240-
#' style_dir("path/to/dir", filetype = c("rmd", ".R"))
239+
#' if (FALSE) {
240+
#' style_dir("path/to/dir", filetype = c("rmd", ".R"))
241241
#'
242-
#' # the following is identical (because of ... and defaults)
243-
#' # but the first is most convenient:
244-
#' style_dir(strict = TRUE)
245-
#' style_dir(style = tidyverse_style, strict = TRUE)
246-
#' style_dir(transformers = tidyverse_style(strict = TRUE))
242+
#' # the following is identical (because of ... and defaults)
243+
#' # but the first is most convenient:
244+
#' style_dir(strict = TRUE)
245+
#' style_dir(style = tidyverse_style, strict = TRUE)
246+
#' style_dir(transformers = tidyverse_style(strict = TRUE))
247247
#' }
248248
#' @export
249249
style_dir <- function(path = ".",

man/parse_safely.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/set_and_assert_arg_filetype.Rd

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/set_line_break_before_curly_opening.Rd

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_dir.Rd

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)