Message-ID: <74862bb1-0878-2634-04a4-89137709a202@gmail.com>
Date: 2019-09-27T12:36:00Z
From: Duncan Murdoch
Subject: [R-pkg-devel] Passing CRAN check when an examples must save a file
In-Reply-To: <CACfhunRiNMJcaymDMoJZQYd63Ac0wBB-CSUxF5ynf3B=Ohcjjg@mail.gmail.com>
On 26/09/2019 11:43 p.m., Zachary Flynn wrote:
> I am working on a function in a package that saves a file. I want to write
> an example to document the function so it must save a file, but when I do,
> the automatic CRAN checks reject the package because there is a
> non-standard file saved in the directory when the second test runs (first,
> it runs a test on Windows where the check error does not occur, then on
> Linux where it does). The relevant check output is:
>
> * checking for non-standard things in the check directory ... NOTE
> Found the following files/directories:
> ?Produc.csv?
>
> There is no file called Produc.csv anywhere in the directory (the
> error doesn't show up in the first run on Windows).
>
> It is generated by running the example code which automatic CRAN
> testing might be doing in between running the Windows and Linux
> checks?
>
> How do I write an example that must save a file to be an example of
> using the function without triggering this issue?
Save the file to the temporary directory, ?.g.
filename <- file.path(tempdir(), "Prod?c.csv")
write.csv(something, file = filename)
You could clean up at the end of the example with
unlink(filename)
but you shouldn't rely on this alone to prevent the error: if you're
writing files, you should *only* be doing it in the temporary directory.
Duncan Murdoch