Skip to content

Commit 901d9ed

Browse files
Remove local_tempfile() usage in examples following breakage by withr 3.0.0 (#2519)
* debugging * dont use withr in examples * kwarg for cat()
1 parent bad1632 commit 901d9ed

15 files changed

+69
-44
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Config/Needs/development: pkgload, cli, testthat, patrick
5656
Config/testthat/edition: 3
5757
Encoding: UTF-8
5858
Roxygen: list(markdown = TRUE)
59-
RoxygenNote: 7.2.3
59+
RoxygenNote: 7.3.1
6060
Collate:
6161
'make_linter_from_xpath.R'
6262
'xp_utils.R'

R/get_source_expressions.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@
5454
#' \item{lines}{The [readLines()] output for this file.}
5555
#' }
5656
#'
57-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
58-
#' tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
57+
#' @examples
58+
#' tmp <- tempfile()
59+
#' writeLines(c("x <- 1", "y <- x + 1"), tmp)
5960
#' get_source_expressions(tmp)
61+
#' unlink(tmp)
6062
#' @export
6163
get_source_expressions <- function(filename, lines = NULL) {
6264
source_expression <- srcfile(filename, encoding = settings$encoding)

R/ids_with_token.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
#' the `token` column of `parsed_content`. Typically `==` or `%in%`.
1818
#' @param source_file (DEPRECATED) Same as `source_expression`. Will be removed.
1919
#'
20-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
21-
#' tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
20+
#' @examples
21+
#' tmp <- tempfile()
22+
#' writeLines(c("x <- 1", "y <- x + 1"), tmp)
2223
#' source_exprs <- get_source_expressions(tmp)
2324
#' ids_with_token(source_exprs$expressions[[1L]], value = "SYMBOL")
2425
#' with_id(source_exprs$expressions[[1L]], 2L)
26+
#' unlink(tmp)
2527
#'
2628
#' @return `ids_with_token`: The indices of the `parsed_content` data frame
2729
#' entry of the list of source expressions. Indices correspond to the

R/is_lint_level.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#' means an individual expression, while `"file"` means all expressions
1010
#' in the current file are available.
1111
#'
12-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
13-
#' tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
12+
#' @examples
13+
#' tmp <- tempfile()
14+
#' writeLines(c("x <- 1", "y <- x + 1"), tmp)
1415
#' source_exprs <- get_source_expressions(tmp)
1516
#' is_lint_level(source_exprs$expressions[[1L]], level = "expression")
1617
#' is_lint_level(source_exprs$expressions[[1L]], level = "file")
1718
#' is_lint_level(source_exprs$expressions[[3L]], level = "expression")
1819
#' is_lint_level(source_exprs$expressions[[3L]], level = "file")
20+
#' unlink(tmp)
1921
#'
2022
#' @export
2123
is_lint_level <- function(source_expression, level = c("expression", "file")) {

R/lint.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
#'
2727
#' @return An object of class `c("lints", "list")`, each element of which is a `"list"` object.
2828
#'
29-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
30-
#' f <- withr::local_tempfile(lines = "a=1", fileext = "R")
29+
#' @examples
30+
#' f <- tempfile()
31+
#' writeLines("a=1", f)
3132
#' lint(f) # linting a file
3233
#' lint("a = 123\n") # linting inline-code
3334
#' lint(text = "a = 123") # linting inline-code
35+
#' unlink(f)
3436
#'
3537
#' @export
3638
lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings = TRUE, text = NULL) {

R/trailing_blank_lines_linter.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
#'
33
#' Check that there are no trailing blank lines in source code.
44
#'
5-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
5+
#' @examples
66
#' # will produce lints
7-
#' f <- withr::local_tempfile(lines = "x <- 1\n")
8-
#' readLines(f)
7+
#' f <- tempfile()
8+
#' cat("x <- 1\n\n", file = f)
9+
#' writeLines(readChar(f, file.size(f)))
910
#' lint(
1011
#' filename = f,
1112
#' linters = trailing_blank_lines_linter()
1213
#' )
14+
#' unlink(f)
1315
#'
1416
#' # okay
15-
#' f <- withr::local_tempfile(lines = "x <- 1")
16-
#' readLines(f)
17+
#' cat("x <- 1\n", file = f)
18+
#' writeLines(readChar(f, file.size(f)))
1719
#' lint(
1820
#' filename = f,
1921
#' linters = trailing_blank_lines_linter()
2022
#' )
23+
#' unlink(f)
2124
#'
2225
#' @evalRd rd_tags("trailing_blank_lines_linter")
2326
#' @seealso [linters] for a complete list of linters available in lintr.

R/utils.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,24 @@ platform_independent_sort <- function(x) x[platform_independent_order(x)]
221221
#' and `xpath` is specified, it is extracted with [xml2::xml_find_chr()].
222222
#' @param xpath An XPath, passed on to [xml2::xml_find_chr()] after wrapping with `string()`.
223223
#'
224-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
225-
#' tmp <- withr::local_tempfile(lines = "c('a', 'b')")
224+
#' @examples
225+
#' tmp <- tempfile()
226+
#' writeLines("c('a', 'b')", tmp)
226227
#' expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content
227228
#' writeLines(as.character(expr_as_xml))
228229
#' get_r_string(expr_as_xml, "expr[2]") # "a"
229230
#' get_r_string(expr_as_xml, "expr[3]") # "b"
231+
#' unlink(tmp)
230232
#'
231233
#' # more importantly, extract strings under R>=4 raw strings
232234
#' @examplesIf getRversion() >= "4.0.0"
233-
#' tmp4.0 <- withr::local_tempfile(lines = "c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')")
235+
#' tmp4.0 <- tempfile()
236+
#' writeLines("c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')", tmp4.0)
234237
#' expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content
235238
#' writeLines(as.character(expr_as_xml4.0))
236239
#' get_r_string(expr_as_xml4.0, "expr[2]") # "a\\b"
237240
#' get_r_string(expr_as_xml4.0, "expr[3]") # "a\\\"'\"\\b"
241+
#' unlink(tmp4.0)
238242
#'
239243
#' @export
240244
get_r_string <- function(s, xpath = NULL) {

R/with.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ all_linters <- function(..., packages = "lintr") {
149149
#'
150150
#' @param defaults Default list of linters to modify. Must be named.
151151
#' @inheritParams linters_with_tags
152-
#' @examplesIf requireNamespace("withr", quietly = TRUE)
152+
#' @examples
153153
#' # When using interactively you will usually pass the result onto `lint` or `lint_package()`
154-
#' f <- withr::local_tempfile(lines = "my_slightly_long_variable_name <- 2.3", fileext = "R")
154+
#' f <- tempfile()
155+
#' writeLines("my_slightly_long_variable_name <- 2.3", f)
155156
#' lint(f, linters = linters_with_defaults(line_length_linter = line_length_linter(120L)))
157+
#' unlink(f)
156158
#'
157159
#' # the default linter list with a different line length cutoff
158160
#' my_linters <- linters_with_defaults(line_length_linter = line_length_linter(120L))

man/get_r_string.Rd

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

man/get_source_expressions.Rd

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

man/ids_with_token.Rd

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

man/is_lint_level.Rd

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

man/lint.Rd

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

man/linters_with_defaults.Rd

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

man/trailing_blank_lines_linter.Rd

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

0 commit comments

Comments
 (0)