Thanks! Generally-speaking, I wonder if it'd be useful to have a separate command, like modules::import_defaults() that uses the modules-centric way to import all of the standard default packages (perhaps with the exception of datasets) at the start of some module (whether in-line or as a script-file).
Pros:
- Not requiring users to try to figure out which 'standard' command is in which 'standard' package. For example, is
mean() in base? Is it in utils? Is it in stats (because the mean, after all, is a type of summary statistic)? (Spoiler, it's in base.) What about runif()? Sampling a random value uniformly between [0,1] is so basic to programming languages, it might be in base, right? Nope, it's in stats. Well, then it makes sense that sample() is probably in stats, too, right? Nope, it's in base. 🤦
- For any module that eventually tries to
plot() something, requiring like the explicit import of both graphics and grDevices is likely going to trip-up lots of users.
- ^ Likewise with needing to import
methods if those users want to try some S4OO programming in their module. (This'll bring traumatizing flashbacks to old-timers who remember the days of needing to library(methods) at the start of every script for R < 3.0 :-)
Cons:
- It attaches lots to the module's namespace. (Though I'm not sure if there's really any extra memory usage, since these are all loaded into memory already when starting R, unless one's overridden the
options()$defaultPackages, in which case I'd argue such power-users already know what they're doing.)
- If the default list of packages ever changes in a future R release, this can cause some mild confusion. Though I'd argue that if the default list ever changes, confusion will happen no matter what, whether a
modules user or not.
Also, I'm just now reading #14, and in the stats::lag/dplyr::lag example, wouldn't ordered imports in modules still provide masking? E.g.
modules::import("stats")
modules::import("dplyr")
lag ## dplyr's lag, not stats's lag.
If someone really wanted to use stats's lag(), they could bypass what they've imported and just refer to it explicitly, with stats::lag(), no?
This does introduce complexity of masking within the modules paradigm and how to refer to one-vs-the-other object specifically within imported modules (e.g. user-defined functions), since the :: notation won't work. So, file that problem under the "Con" department, I guess :-/
Though, this is only a problem if people aren't assigning modules to variables, in which case they're inviting their own confusion; so I'd still consider 'attaching' the default packages' contents then emphasizing that users should import modules with explicit variable assignment a la foo <- modules::import("foo").
Originally posted by @mmuurr in #13 (comment)
Thanks! Generally-speaking, I wonder if it'd be useful to have a separate command, like
modules::import_defaults()that uses themodules-centric way to import all of the standard default packages (perhaps with the exception ofdatasets) at the start of some module (whether in-line or as a script-file).Pros:
mean()inbase? Is it inutils? Is it instats(because the mean, after all, is a type of summary statistic)? (Spoiler, it's inbase.) What aboutrunif()? Sampling a random value uniformly between [0,1] is so basic to programming languages, it might be inbase, right? Nope, it's instats. Well, then it makes sense thatsample()is probably instats, too, right? Nope, it's inbase. 🤦plot()something, requiring like the explicit import of bothgraphicsandgrDevicesis likely going to trip-up lots of users.methodsif those users want to try some S4OO programming in their module. (This'll bring traumatizing flashbacks to old-timers who remember the days of needing tolibrary(methods)at the start of every script for R < 3.0 :-)Cons:
options()$defaultPackages, in which case I'd argue such power-users already know what they're doing.)modulesuser or not.Also, I'm just now reading #14, and in the
stats::lag/dplyr::lagexample, wouldn't ordered imports inmodulesstill provide masking? E.g.If someone really wanted to use
stats'slag(), they could bypass what they've imported and just refer to it explicitly, withstats::lag(), no?This does introduce complexity of masking within the
modulesparadigm and how to refer to one-vs-the-other object specifically within imported modules (e.g. user-defined functions), since the::notation won't work. So, file that problem under the "Con" department, I guess :-/Though, this is only a problem if people aren't assigning modules to variables, in which case they're inviting their own confusion; so I'd still consider 'attaching' the default packages' contents then emphasizing that users should import modules with explicit variable assignment a la
foo <- modules::import("foo").Originally posted by @mmuurr in #13 (comment)