Skip to content

Commit

Permalink
Merge pull request #69 from aitap/detritus
Browse files Browse the repository at this point in the history
"Found detritus in the temp directory"
  • Loading branch information
Baltmann01 authored Nov 25, 2024
2 parents 6a87aed + 4dd0a62 commit e5e4b54
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions code_issues.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,29 @@ Packages can write per default to `tempdir()`, or any other temporary/cache dire

<!-- tbd: add section about R_user_dir() -->

---------------------------------------

# Leaving Files in the Temporary Directory

## Problem

Some of your code that runs during ` R CMD check ` creates files in the temporary directory specified by the environment variable `TMPDIR` and doesn't remove them afterwards. As a result, ` R CMD check ` gives your package a NOTE complaining about the "detritus in the temp directory".

## Solution

If you use `tempfile()`/`tempdir()` as the default destination for functions called in your examples or tests, `unlink()` the resulting files as part of the test. In the `\examples{}` section of your help files, clean-up actions can be wrapped in `\dontshow{}` for aesthetic reasons. If you launch a browser, 'Calibre', 'Python' code or other software, and it creates temporary files, find out where they are and remove them once the code is done with them.

### Details

::: {.callout-note title="CRAN NOTE" icon=false}
Check: for detritus in the temp directory, Result: NOTE\
&emsp; Found the following files/directories:\
&emsp;&emsp; ‘this\_is\_detritus382e569a7712’
:::

The code responsible for the detritus may include your own tests and examples creating files under `tempdir()`, child processes, or 'Python' code launched using 'reticulate'. For example, R packages that use the 'tensorflow' 'Python' package [find and remove temporary files created by its auto-gradient feature](https://github.com/cran/vetiver/blob/35b24768cf0e84fab96610e001bba377dc777953/tests/testthat/setup.R#L13).

A package that uses the 'testthat' test suite will benefit from [the self-cleaning functions `withr::local_tempfile()` and `withr::local_tempdir()`](https://r-pkgs.org/testing-design.html#sec-tests-files-where-write) to work with temporary files. Even without 'testthat', the 'withr' package has no external strong dependencies and can be used independently.

---------------------------------------

Expand Down

0 comments on commit e5e4b54

Please sign in to comment.