klmr / box

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

Repeated `use` repeats attachments #251

Closed mmuurr closed 2 years ago

mmuurr commented 2 years ago

Error description

This is probably intentional (to guarantee precedence that aligns with order-of-use calls), but just in case it's not intentional, I figured it was worth pointing out.

box::use(tibble[tibble])  ## call 1
box::use(tibble[tibble])  ## call 2
search()
#  [1] ".GlobalEnv"        "mod:tibble"        "mod:tibble"        "ESSR"
#  [5] "package:stats"     "package:graphics"  "package:grDevices" "package:datasets"
#  [9] "renv:shims"        "package:utils"     "package:methods"   "Autoloads"
#  [13] "package:base"
ls(2)
#  [1] "tibble"
ls(3)
#  [1] "tibble"

... i.e. repeated uses simply repeat attachment (in this trivial example, unnecessarily).

Again, I can imagine cases where this is actually desirable (specifically to deal with naming conflicts), but just in case it's not expected, now you know :-)

R version

platform       x86_64-apple-darwin19.6.0
 arch           x86_64
 os             darwin19.6.0
 system         x86_64, darwin19.6.0
 status
 major          4
 minor          0.3
 year           2020
 month          10
 day            10
 svn rev        79318
 language       R
 version.string R version 4.0.3 (2020-10-10)
 nickname       Bunny-Wunnies Freak Out

‘box’ version

1.1.0

klmr commented 2 years ago

Thanks for reporting it, this is not intentional (see #178), although I can see the argument regarding naming conflicts (and I hadn’t yet thought of that!).

Just for completeness, let me also point out the new auto-reload feature (#246) I’m currently testing, which will prevent repeated attachment during module development/testing at least (if the user enabled auto-reload mode via box::enable_autoreload()).