[R-pkg-devel] Removing packages files

Lluís Revilla ||u|@@rev|||@ @end|ng |rom gm@||@com
Fri Jan 3 17:46:36 CET 2025


The data is mostly CRAN's own files transformed, I don't expect the
download to be problematic on CRAN's checks.
The R core members made the functionality inside tools to use a local
variable to search for the requested file locally.
Only if the file is not found they are downloaded from the internet.

Regarding tests, I could disable saving the content to a file (Thanks
for mentioning, I hadn't thought about it).
But the functionality/utility of the package is to transform CRAN's data.
If it is failing to do so, I would like to know.

Lluís

On Fri, 3 Jan 2025 at 17:23, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>
> On 2025-01-03 10:04 a.m., Lluís Revilla wrote:
> > Thanks Henrik for confirming there is nothing similar currently.
> >
> > Duncan: Letting the user choose when to remove the folder/data at will is easy.
> > I was trying to ensure that the system is clean after removing the package.
> > Thanks.
>
> No, I was suggesting that you require the user to explicitly ask for the
> data.  You don't want CRAN to install the data during testing and then
> have it left behind at the end.
>
> Duncan Murdoch
>
> >
> > On Thu, 2 Jan 2025 at 22:42, Henrik Bengtsson
> > <henrik.bengtsson using gmail.com> wrote:
> >>
> >> As a first step, this sounds like something for the 'tools' package,
> >> e.g. tools::cleanup_R_user_dir() that wipes package subfolders of
> >> packages no longer installed, or the specified package, iff given.
> >> With that in place, one could argue for adding a 'cleanup' argument to
> >> remove.packages() that use the former.
> >>
> >> Agree, it would be neat if a package could clean up after itself when
> >> uninstalled.
> >>
> >> /Henrik
> >>
> >> On Thu, Jan 2, 2025 at 1:37 PM Lluís Revilla <lluis.revilla using gmail.com> wrote:
> >>>
> >>> Dear Duncan,
> >>>
> >>> Thank you for your answer. I checked again and made a mock package
> >>> that removes a file with .onDetach.
> >>> The file was not removed upon uninstalling the package.
> >>>
> >>> Lluís
> >>>
> >>> On Thu, 2 Jan 2025 at 17:23, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
> >>>>
> >>>> 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
> >>>>
> >>>
> >>> ______________________________________________
> >>> R-package-devel using r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list