-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First draft of auto-reload functionality #246
base: main
Are you sure you want to change the base?
Conversation
Nice! Looks really clean, although I feel I don't know enough low-level R to properly review this. I think I can follow the code for tracking the file changes, I don't get where this actually hooks into the |
@grst The relevant changes are in Lines 372 to 392 in ac3f691
|
@grst I’d be grateful if you could test-drive the pull request. The implementation is pretty crude, I’m sure there are situations which I’ve overlooked in my tests, and real-world usage is necessary to improve the implementation. To install, open R and run install.packages('https://github.com/klmr/box/files/7192969/box_1.1.9000.tar.gz', type = 'source', repos = NULL) … or download the archive and run the command locally. As far as I’m aware, the code is feature complete — except no unload hook is being run. I haven’t decided yet whether to do this. Manual The API is also still subject to change: I’m not happy with the current names, they’re too long for my taste. I might shorten |
I'll give it a try this week! |
@grst You may want to hold off on testing, Iʼve already found a bug in combination with Shiny, and I havenʼt got a fix yet. |
@grst OK, fixed that bug. New archive: |
I currently get the following error when starting my shiny app:
EDIT: I installed the latest version of this branch using |
Unfortunately that won’t work since I’m not checking generated code ( |
I see! If I use the archive For instance, in my
If I change something in |
Actually, by using Is that expected? I thought with shiny, we wouldn't even need the |
Ah yes, the current default mode of This works if your When it’s at file scope as in your case, you’ll need to pass As mentioned, the only reason this isn’t the default currently is that it’s less efficient. However, the whole point of testing is to figure out what would be most convenient for the user: I’m more than happy to change the default behaviour if we find that that’s more appropriate. So please let me know what you think, and whether you have any ideas for a better syntax, or other configuration options you find worth having. Incidentally, |
EDIT: |
How useful is it to be able to configure which modules are auto-reloaded (via
… as with the Using options rather than functions to configure auto-reloading is less powerful: there’s currently no provision for excluding modules from auto-reload, and no way to enable or disable auto-reload mode inside a running R session — the ‘box’ package would have to be unloaded and reloaded before changed options would take effect. On the flip side, I think it would simplify documentation and usage. |
So far, I didn't run into any situation where I'd have had to exclude certain files from autoreloading. However, one situation where I believe this could be useful is if there is a short-running function that is called many times. In that case the overhead of checking if the file was modified could become significant. But then again, I could simply not use the Lastly, I find the proposed naming of the options slightly confusing: At the first glance I thought |
slightly off-topic... I love {box} and its functionality and the auto-reload/invalidate-cache functionality would help in my use-case a lot (I currently use box inside of shiny applications). A current workaround is taken from rhino where the following two-liner invalidates the whole box-cache: loaded_mods <- loadNamespace("box")$loaded_mods
rm(list = ls(loaded_mods), envir = loaded_mods) |
b67501d
to
216f3ca
Compare
Work in progress implementation of #234.
The first draft includes auto-reloading for subsequent
box::use
calls:box::enable_autoreload()
enables auto-reloading forbox::use
calls only. This solution should work e.g. for Shiny applications. But it won’t work well inside scripts and R Markdown documents, sincebox::use
is required to trigger a reload.box::disable_autoreload()
disables auto-reloading.box::enable_autoreload
acceptsinclude
andexclude
arguments to limit which modules get auto-reloaded:box::enable_autoreload(include = c(./a, my/mod, foo/bar))
box::enable_autoreload(include = foo/bar)
exclude
box::autoreload_include(...)
andbox::autoreload_exclude(...)
add includes or excludes after auto-reloading has been enabled./a
imports./b
andb.r
changes, thenbox::use(./a)
won’t reload eithera.r
orb.r
, since only the (unchanged) timestamp ofa.r
is checked.Well, that’s about it for now.
Still to be done:
mod$x
).on_load
/cc @grst for feedback