I think you can simplify this to:

```r
.test_code <- function(code, reporter = "greedy", path = tempfile(fileext = ".R")) {
  writeLines(code, path)
  on.exit(unlink(path))

  test_file(filename, reporter)$results
}
```

and then remove the directory changing/deleting code below