-
Hi! I am tinkering with Is there a way to escape "local" reloading and make the following example reload the module from within the function in this example? writeLines("foo <- 1", "module.R")
box::use(./module)
module$foo
# [1] 1
writeLines("foo <- 2", "module.R")
box::reload(module)
module$foo
# [1] 2
writeLines("foo <- 3", "module.R")
f <- function() { box::reload(module); module$foo }
f()
# [1] 3
module$foo
# [1] 2 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It certainly does! And, since it’s intended exclusively for interactive development, it is designed to be only ever called from the global environment (and on modules that are loaded in the global environment). Calling it from anywhere else doesn’t really make sense, except (as I suspect you are trying to) inside a function that acts as a convenience shortcut for interactive use. — If this isn’t your intended use, would you mind telling me more about your use-case? Maybe I have a better solution, or this is a legitimate use-case I hadn’t thought of, and which ‘box’ should accommodate in the future. At any rate, you can make your code work with a bit of scope hackery: f <- function() {
evalq(box::reload(module), envir = parent.frame())
module$foo
} |
Beta Was this translation helpful? Give feedback.
It certainly does! And, since it’s intended exclusively for interactive development, it is designed to be only ever called from the global environment (and on modules that are loaded in the global environment). Calling it from anywhere else doesn’t really make sense, except (as I suspect you are trying to) inside a function that acts as a convenience shortcut for interactive use. — If this isn’t your intended use, would you mind telling me more about your use-case? Maybe I have a better solution, or this is a legitimate use-case I hadn’t thought of, and which ‘box’ should accommodate in the future.
At any rate, you can make your code work with a bit of scope…