I'm developing a package that can inject yaml data in the yaml header of a Quarto document. I've some examples of this in the documentation of my package. The examples consist in making a temporary file, injecting the data and printing the output (see below).
I know that making temporary things usually implies destroying or undoing them later. I knew about on.exit()
but only recently heard of test fixtures, and although I understand the benefit of using them, I'm not quite sure yet to understand all the disadvantages and consequences of not using them.
From what I understood from Self-cleaning test fixtures, test fixtures are usually meant to be used internally, in function environments, not so much outside of them. And as the name suggests, they are essentially useful for testing.
Does this mean that when creating e.g. a temporary file to serve as an example in the documentation (either vignette or function example), it's not necessary to destroy it after the example?
Here's a simplified version of the example I use in on of the vignettes. Does it make sense to undo the temporary file or use e.g. withr::local_tempfile()
here?
```{r, include = FALSE}
# make a temp file assigned to the variable `tmp`
```
Blah blah…
```{r, echo = FALSE, comment = ""}
cat(readr::read_file(tmp))
to_yaml(data, tmp)
cat(readr::read_file(tmp))
```