Local module sourcing occasionally fails with RStudio run
- Dominant language
- R
- Stars
- 979
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
### Error description
When interactively developing in RStudio, I often might run selections of code by running line by line or highlighting a section to run with `cmd + enter` or the `Run` button. This occasionally generates errors when running `box::use(local/module)`, even though the relative sourcing is correct. Below is an example with two modules `a` and `b` in the same directory:
`a.R`
```r
#' Title
#' @export
a <- function() {
print("I am a")
}
```
`b.R`
```r
box::use(./a)
a$a()
```
If I open up `b.R` and highlight the code and run, it is successful:

However, if I leave the same code block highlighted, restart my R session, and click run without re-highlighting the code, it fails, indicating that it is unable to load module `a` in my current project directory.

However, clicking back on the `b.R` script and running line by line or re-highlighting will successfully run. With more complex modules with multiple imports, running code line by line can generate the same error, where it seems the RStudio pathing has lost track of the source file and defaults to project directory or base directory, depending if in a project environment or not.
I can explore a more complex reprex if helpful. This is not a critical bug, but something other colleagues have noticed so flagging here.
### R version
```plain text
_
platform x86_64-apple-darwin20
arch x86_64
os darwin20
system x86_64, darwin20
status
major 4
minor 3.3
year 2024
month 02
day 29
svn rev 86002
language R
version.string R version 4.3.3 (2024-02-29)
nickname Angel Food Cake
```
### RStudio version
```
$mode
[1] "desktop"
$version
[1] ‘2023.12.1.402’
$long_version
[1] "2023.12.1+402"
$release_name
[1] "Ocean Storm"
```
### ‘box’ version
‘1.2.0’
Contributor guide
Research direction
Reproduce the behavior with the two-module a.R and b.R example in RStudio, especially after restarting the R session and running without re-highlighting. Start by tracing how box::use(./a) determines the source file during interactive execution. Done means local module loading is reliable for the described RStudio run modes, with a regression test covering the failure scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100