klmr / box

Write reusable, composable and modular R code
https://klmr.me/box/
MIT License
829 stars 47 forks source link

Warning Message Appears When Reloading a Module #363

Closed thothal closed 1 week ago

thothal commented 2 months ago

Error description

Assume the following modules:

dbg/a.R

#' Title
#' @export
a <- function() {
  print("I am a")
}

dbg/b.R

box::use(dbg/a)
#' Title
#' @export
b <- function() {
  print("I am b and call a")
  a$a()
}

dbg/c.R

box::use(dbg/a)
box::use(dbg/b)

#' Title
#' @export
c <- function() {
  print("I am c and call a and b")
  a$a()
  b$b()
}

When trying to reload module c you get the following error:

box::use(dbg/c)
box::reload(c)
# Warning message:
# In rm(list = info$source_path, envir = loaded_mods) :
#   object '<path stripped>\\dbg\\a.R' not found

Issue lies within box:::deregister_mod where we try to remove the module. Because it is loaded twice (once via dbg/b and once via dbg/c) the second attempt to delete it will eventually raise the warning, which I consider spurious.

Easy fix would be to muffle it or to include some chekc to see whether the module is still in loaded_mods.

R version

_                                
platform       x86_64-w64-mingw32               
arch           x86_64                           
os             mingw32                          
crt            ucrt                             
system         x86_64, mingw32                  
status                                          
major          4                                
minor          2.2                              
year           2022                             
month          10                               
day            31                               
svn rev        83211                            
language       R                                
version.string R version 4.2.2 (2022-10-31 ucrt)
nickname       Innocent and Trusting

‘box’ version

1.2.0