R: Run code on setup/teardown

teardown {testthat} | R Documentation

## Run code on setup/teardown

### Description

Code in a `setup()` block is run immediately in a clean environment. Code in a `teardown()` block is run upon completion of a test file, even if it exits with an error. Multiple calls to `teardown()` will be executed in the order they were created.

### Usage

    teardown(code, env = parent.frame())

    setup(code, env = parent.frame())

### Arguments

`code` | Code to evaluate
`env` | Environment in which code will be evaluted. For expert use only.

### Examples

    ## Not run:

    tmp <- tempfile()
    setup(writeLines(tmp, "some test data"))
    teardown(unlink(tmp))

    ## End(Not run)

[Package testthat version 2.0.1 Index]