Skip to content

Support for temporary files and directories #828

Closed
@gaborcsardi

Description

@gaborcsardi

These should be cleaned up, so it would be nice to support them "natively". E.g. something like:

tmpf <- test_temp_file()
tmpd <- test_temp_dir(cleanup = "block")

cleanup can be block or file or testsuite, to specify when to clean up the files.

withr::local_tempfile() is almost good, and testthat could use it internally, but it is annoying that it fails if you copy and paste a test case to the console:

withr::local_tempfile("foobar")
Error in defer(unlink(mget(new, envir = envir)), envir = envir) :
  attempt to defer event on global environment

The testthat function could just ignore these calls.

Happy to do a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions