klmr / klmr/box

autoreload feature

Open
#234 11 comments 2 reactions 1 assignee Claimed by @klmr View on GitHub
✨ new feature 🛠 work in progress
Dominant language
R
Stars
979
Forks
49
PR merge metrics
No merged PRs in 30d

Description

While developing interactively, it would be fantastic if the modules are re-loaded automatically in the background every time a module has changed. This is how the [`%autoreload`](https://ipython.org/ipython-doc/3/config/extensions/autoreload.html) magic works in jupyter notebooks.

## Use-case

### 1. Working on rmarkdown documents

I believe it is considered good practice to only have the code directly needed for generating the report within the rmarkdown document itself and to refactor helper functions into a separate file. Now, if I work on the document and have my helper functions loaded with, say `box::use(./utils)`, I need to run `reload(utils)` every time I change a utility function.

### 2. Modular shiny apps

I found that box is a quite effective way to structure modular shiny apps. The only downside is that when hitting the "Reload App" button in Rstudio wil not reload any changes I made to the shiny modules I loaded with box. My current workaround is to have a `reload(module)` right underneath each `use(module)`.

## Suggested implementation

Enable autoreload by setting a global configuration flag, e.g.

```r
box::set_autoreload(TRUE)

# or borrowing flags from ipython's %autoreload
box::set_autoreload(2)
```

I don't know how this would work under-the-hood, but probably watch all files from which functions have been imported and
trigger `box::reload` every time a file has changed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.