Skip to content

Commit

Permalink
use a fixed path by default for the dev.path argument in record() to …
Browse files Browse the repository at this point in the history
…avoid littering the working directory with random plot files
  • Loading branch information
yihui committed Apr 28, 2024
1 parent 55914e5 commit f1eb5c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: xfun
Type: Package
Title: Supporting Functions for Packages Maintained by 'Yihui Xie'
Version: 0.43.7
Version: 0.43.8
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Wush", "Wu", role = "ctb"),
Expand Down
13 changes: 6 additions & 7 deletions R/record.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
#' @param dev A graphics device. It can be a function name, a function, or a
#' character string that can be evaluated to a function to open a graphics
#' device.
#' @param dev.path A base file path for plots (by default, a temporary path
#' under the current working directory). Actual plot filenames will be this
#' base path plus incremental suffixes. For example, if `dev.path = "foo"`,
#' the plot files will be `foo-1.png`, `foo-2.png`, and so on. If `dev.path`
#' is not character (e.g., `FALSE`), plots will not be recorded.
#' @param dev.path A base file path for plots. Actual plot filenames will be
#' this base path plus incremental suffixes. For example, if `dev.path =
#' "foo"`, the plot files will be `foo-1.png`, `foo-2.png`, and so on. If
#' `dev.path` is not character (e.g., `FALSE`), plots will not be recorded.
#' @param dev.ext The file extension for plot files. By default, it will be
#' inferred from the first argument of the device function if possible.
#' @param dev.args Extra arguments to be passed to the device. The default
Expand All @@ -35,15 +34,15 @@
#' @import grDevices
#' @export
#' @examples
#' code = c('# a message test', '1:2 + 1:3', 'par(mar = c(4, 4, 1, .2))', 'barplot(5:1, col = 2:6, horiz = TRUE)', 'head(iris)', "sunflowerplot(iris[, 3:4], seg.col = 'purple')", "if (TRUE) {\n message('Hello, xfun::record()!')\n}", '# throw an error', "1 + 'a'")
#' code = c('# a warning test', '1:2 + 1:3', 'par(mar = c(4, 4, 1, .2))', 'barplot(5:1, col = 2:6, horiz = TRUE)', 'head(iris)', "sunflowerplot(iris[, 3:4], seg.col = 'purple')", "if (TRUE) {\n message('Hello, xfun::record()!')\n}", '# throw an error', "1 + 'a'")
#' res = xfun::record(code, dev.args = list(width = 9, height = 6.75), error = TRUE)
#' xfun::tree(res)
#' format(res)
#' # find and clean up plot files
#' plots = Filter(function(x) inherits(x, 'record_plot'), res)
#' file.remove(unlist(plots))
record = function(
code = NULL, dev = 'png', dev.path = tempfile('record-', '.'),
code = NULL, dev = 'png', dev.path = 'xfun-record',
dev.ext = dev_ext(dev), dev.args = list(), error = FALSE, cache = list(),
verbose = getOption('xfun.record.verbose', 0), envir = parent.frame()
) {
Expand Down
12 changes: 5 additions & 7 deletions man/record.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1eb5c5

Please sign in to comment.