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
When one evaluates
library(foo)
, R first loads the package foo in to memory, and then attaches the package to thesearch()
path. Other operations, such asloadNamespace("foo")
orfoo::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 ofsearch()
. Since tools isn't attached, the symbols in tools are not resolved.Nonetheless, one has access to them with
tools::file_ext
, whether tools is on the search path or not.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: