-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
globalenv on search path of a module #151
Comments
That’s entirely correct, and this is in fact the intended behaviour of ‘modules’.
We … don’t. That’s a bug. |
Hmm. Actually, there is a reason why the behaviour is as currently seen; namely, to make ease of migration from plain scripts to modules easier: since many plain R scripts use objects from the default attached packages (‘stats’, ‘grDevices’, ‘methods’ etc.), we need to ensure that these objects continue to be available without explicitly qualifying their package name. There are two possible ways of ensuring this:
The second way would ensure that packages can continue to be used, but skip the global environment for lookup. |
Check out the new release, 0.9.13. It should be fixed now. Incidentally version 1.0 of modules (if I ever get around to releasing it …), which is a backwards incompatible rewrite, will handle this way stricter: no (non-‘base’) package will be attached inside a module any more, even other default packages. Every object access must be either fully qualified or explicitly use-attached. |
@klmr This might not be the best place to make this comment, but I just wanted to say that I am eagerly awaiting the CRAN release of version 1.0 with the new API. I hope you get around to releasing it :) |
Thanks for the quick fix. Consider the following senario: what if a careless user accidentally use library(somepackage) in some.Rscript, then somepackage will be on the search path of module1.R. Not sure if it is appropriate to instead use |
Yes. This is unfortunate, and why future versions of modules will behave differently. But in the current version of modules, this is by design because many existing modules (which were created from existing R scripts) rely on this behaviour. It can’t be changed without breaking backwards compatibility in a big way. |
I tried to use modules to manage my R codebase. It seems that each module will have base namespace on its search path, since global env is parent of base namespace, global env will also be on the modules's search path. This might cause some problem as shown below:
Say for example, I need to run a R script called some.Rscript, and it imports module1.R:
some.Rscript:
module1.R
module1 can actually see m_pryr since m_pryr will be put into the global env. Generally, I would like to avoid such unsafe behaviors. module1.R shouldn't have access to m_pryr, in my opinion.
I am not sure why we need the base namespace as parent instead of the baseenv. If we have baseenv as parent of the module, global env will not be on any module search path. I am not sure if this is related to S3 method? As I found this about base namespace:
If this is the reason we need to use base namespace instead of base env, is there any way to work around this?
The text was updated successfully, but these errors were encountered: