Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Collate:
'aaa.R'
'collate.R'
Expand Down Expand Up @@ -71,3 +70,4 @@ Collate:
'torture.R'
'utils.R'
'with.R'
Config/roxygen2/version: 8.0.0
21 changes: 21 additions & 0 deletions R/tempfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@
#'
#' # Note that this variable is only available in the scope of with_tempfile
#' try(path2)
#'
#' # local_tempdir() creates a temporary directory and returns its path
#' local({
#' dir_path <- local_tempdir()
#' dir.exists(dir_path)
#' # create a file inside it
#' writeLines("hello", file.path(dir_path, "test.txt"))
#' file.exists(file.path(dir_path, "test.txt"))
#' })
#' # the directory and its contents are deleted automatically
#' file.exists(dir_path)
#'
#' # with_tempdir() temporarily changes the working directory to a temp dir
#' getwd()
#' with_tempdir({
#' getwd()
#' writeLines("test", "example.txt")
#' list.files()
#' })
#' # the original working directory is restored
#' getwd()
#' @export
with_tempfile <- function(new, code, envir = parent.frame(), .local_envir = parent.frame(),
pattern = "file", tmpdir = tempdir(), fileext = "") {
Expand Down
21 changes: 21 additions & 0 deletions man/with_tempfile.Rd

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

Loading