I start to use the R package box, but struggle during development of nested dependencies.
Setup
Usually I develop a first function helper.R
:
# helper.R
helper <- function(i) {
return(paste("help", i))
}
Then a I use it in a wrapper:
# wrapper.R
box::use(./helper[helper])
lapply(1:3, helper)
Returning:
r$> lapply(1:3, helper)
[[1]]
[1] "help 1"
[[2]]
[1] "help 2"
[[3]]
[1] "help 3"
So far so good :-)
Problem
Do not restart the R-session! Now, I change my helper:
# helper.R
helper <- function(i) {
return(paste("Please help", i))
}
I would like to do box::reload(./helper[helper])
or box::reload("helper")
to use the update helper function, but I get this Error:
"reload" expects a module object, got "helper", which is not a module alias variable
I was expecting that box::name()
would return this "module alias variable", but it does not :-( It returns "helper"
which does not work with box::reload()
.
I am clearly missing some terminology AND/OR syntax here? Can you please clarify how I can reload a local module without restarting the R session?
Thanks!
box::reload
(andbox::unload
) expect a module object as their argument — not a name or path.This means that the following works:
However, ‘box’ does not support reloading attached names. As a workaround you can use the “nuclear” option for now:
In the future, ‘box’ will implement hot code reloading, which will make explicit calls to
box::reload
orbox::purge_cache
mostly unnecessary.