No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
6542c4e
... +6 ...
4be1fd0
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
4 | 4 | #' @template with |
|
5 | 5 | #' @param new `[character vector]`\cr (Deprecated for `local_tempfile()`) Names of temporary file handles to create. |
|
6 | 6 | #' @param envir `[environment]`\cr Environment in which to define the temporary files. |
|
7 | + | #' @param clean `[logical(1)]`\cr A logical indicating if the temporary |
|
8 | + | #' directory should be deleted after use (`TRUE`, default) or left alone (`FALSE`). |
|
9 | + | #' @inheritParams with_collate |
|
7 | 10 | #' @inheritParams base::tempfile |
|
8 | 11 | #' @examples |
|
9 | 12 | #' # check how big iris would be if written as csv vs RDS |
41 | 44 | } |
|
42 | 45 | defer(unlink(mget(new, envir = envir), recursive = TRUE), envir = envir) |
|
43 | 46 | } |
|
47 | + | ||
48 | + | ||
49 | + | #' @rdname with_tempfile |
|
50 | + | #' @export |
|
51 | + | with_tempdir <- function(code, clean = TRUE, |
|
52 | + | pattern = "file", tmpdir = tempdir(), fileext = "") { |
|
53 | + | if (length(clean) > 1 || !is.logical(clean)) { |
|
54 | + | stop("`clean` must be a single TRUE or FALSE", call. = FALSE) |
|
55 | + | } |
|
56 | + | ||
57 | + | tmp <- tempfile(pattern = pattern, tmpdir = tmpdir, fileext = fileext) |
|
58 | + | ||
59 | + | dir.create(tmp) |
|
60 | + | if (clean) { |
|
61 | + | on.exit(unlink(tmp, recursive = TRUE), add = TRUE) |
|
62 | + | } |
|
63 | + | withr::with_dir(tmp, code) |
|
64 | + | } |
|
65 | + | ||
66 | + | #' @rdname with_tempfile |
|
67 | + | #' @export |
|
68 | + | local_tempdir <- function(pattern = "file", tmpdir = tempdir(), |
|
69 | + | fileext = "", .local_envir = parent.frame(), clean = TRUE) { |
|
70 | + | if (length(clean) > 1 || !is.logical(clean)) { |
|
71 | + | stop("`clean` must be a single TRUE or FALSE", call. = FALSE) |
|
72 | + | } |
|
73 | + | ||
74 | + | path <- tempfile(pattern = pattern, tmpdir = tmpdir, fileext = fileext) |
|
75 | + | ||
76 | + | dir.create(path, recursive = TRUE) |
|
77 | + | ||
78 | + | if (isTRUE(clean)) { |
|
79 | + | defer(unlink(path, recursive = TRUE), envir = .local_envir) |
|
80 | + | } |
|
81 | + | ||
82 | + | path |
|
83 | + | } |
Files | Coverage |
---|---|
R | 84.97% |
Project Totals (22 files) | 84.97% |
4be1fd0
0d36e36
74c6e8b
8445e57
bd75c1c
bb07278
dcbb49b
6542c4e