klmr / box

Write reusable, composable and modular R code
https://klmr.me/box/
MIT License
829 stars 47 forks source link

`purge_cache` function missing #349

Closed teotenn closed 7 months ago

teotenn commented 7 months ago

Error description

My version of box is missing the function purge_cache that is documented in the website (https://klmr.me/box/reference/unload.html).

I have box version 1.1.2 installed from CRAN. I know it was built under R 4.1.3 but I am working with R 4.1.2 and we need to keep this version for the time being. Anyway I would expect it to crash but not to be missing.

> box::purge_cache()
Error: 'purge_cache' is not an exported object from 'namespace:box'

I thought of reporting it. Is it a bug or was the function deprecated? Does it have to do with the source or version?

Regardless of the answer, I need a way to load and unload functions during development that are called from modules directly (without an alias). Is there a way to accomplish this? I assume that purge_cache is for that, right? Without such a function, is there a workaround that I could implement? Like deleting some particular environment or something similar?

R version

4.1.2

‘box’ version

1.1.2

klmr commented 7 months ago

box::purge_cache() was only added in ‘box’ v1.1.3. This is also shown in the change log.

You’re right that box::purge_cache() is the correct function for your use-case. If — for some reason — you need to work with an outdated version of ‘box’ you can use the following workaround:

purge_cache = function () {
    eapply(box:::loaded_mods, function (mod_ns) {
        box:::call_hook(mod_ns, '.on_unload', mod_ns)
    }, all.names = TRUE)
    rm(list = names(box:::loaded_mods), envir = box:::loaded_mods)
}