In my package  I open handles to temporary files from c++, pointer to
the objects containing those handles are returned to R as external
pointer objects. The files are deleted when the corresponding R-object
is deleted and the garbage collector runs:
a <- lvec(10, "integer")
Then when the garbage collector runs the file is deleted. However, on
some platforms (probably with lower limits on the maximum number of file
handles a process can have open), I run into the problem that the
garbage collector doesn't run often enough. In this case that means, for
example, that another package of mine using this package generates an
error when its tests are run .
The simplest solution is to add some calls to gc() in my tests. But a
more general/automatic solution would be nice.
e.g. try to open a file, when that fails call the garbage collector and
try again. However, this introduces duplicated code (in this case only
one line, but that can be more), and doesn't help if it is another
function that tries to open a file.