In R, what does it mean for a package to be "loaded via a namespace (and not attached)" in sessionInfo()
?
Edit:
For example:
> sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base ---->>>> loaded via a namespace (and not attached): ---->>>> [1] tools_2.15.2
It means the package (In this case R) can access the package functions/objects, but the user can not without explicitly loading the tools package where as stats, graphics, etc. are loaded and ready to go for the user.
Here's an example:
sessionInfo() file_ext("file.com") tools::file_ext("file.com") sessionInfo()
When one evaluates library(foo)
, R first loads the package foo in to memory, and then attaches the package to the search()
path. Other operations, such as loadNamespace("foo")
or foo::fun
, or when a third party indicates that it imports symbols from foo, load the package but do not attach it to the search path. Since R is a dynamic language, each function call involves a traversal of the available symbols to find the first that matches. It is efficient, and avoids unnecessary name conflicts, by separating the attach and load operations and hence restricting the number of symbols to search.
In the example above, the tools package has been loaded, but not (yet) attached. When one types a symbol at the R command prompt, R looks for the symbol first in the global name space (the first element returned by search()
and if not found then in successive elements of search()
. Since tools isn't attached, the symbols in tools are not resolved.
> file_ext Error: object 'file_ext' not found
Nonetheless, one has access to them with tools::file_ext
, whether tools is on the search path or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With