Skip to content
Back to formatted view

Raw Message

Message-ID: <fa376599-ff9f-4509-bc41-c5f8c0f8e9c9@gmail.com>
Date: 2025-01-02T16:23:40Z
From: Duncan Murdoch
Subject: [R-pkg-devel] Removing packages files
In-Reply-To: <CAN+W6_sjx59W6hGGMyj565smnazws=uasSWbwEHEe7kXT+YLAQ@mail.gmail.com>

On 2025-01-02 9:55 a.m., Llu?s Revilla wrote:
> Hi list,
> 
> I am developing a package that will download some data, and I'd like
> to store it locally to not recalculate it often.
> The CRAN policy requires tools::R_user_dir to be used and "the
> contents are actively managed (including removing outdated material)"
> or using TMPDIR but "such usage should be cleaned up".
> 
> When loading a package there is .onLoad or .onAttach to fill or check
> those files and other settings required for a package. Is there
> something for when a package is removed?
> 
> I found some related functions like .Last or reg.fnalizer and setHook
> or packageEvent but they are about closing a session or don't have a
> specific event for when uninstalling packages via (remove.packages). I
> appreciate any feedback, thanks in advance.
> 

Yes, those are described in section "1.5.3 Load hooks" of writing R 
extensions:

"Packages can use a .onDetach or .Last.lib function (provided the latter 
is exported from the namespace) when detach is called on the package. It 
is called with a single argument, the full path to the installed 
package. There is also a hook .onUnload which is called when the 
namespace is unloaded (via a call to unloadNamespace, perhaps called by 
detach(unload = TRUE)) with argument the full path to the installed 
package?s directory. Functions .onUnload and .onDetach should be defined 
in the namespace and not exported, but .Last.lib does need to be exported."

Duncan Murdoch