preload package in memory without attaching it
Question
What would be a good way to pre-load a bunch of commonly used R packages in memory when I start an R process, but not actually attach them. Preferably in such a way that there are no side effects.
If I do something like:
getNamespace("XML");
The package is loaded and it shows up in sessionInfo()
:
loaded via a namespace (and not attached):
[1] XML_3.6-2
Does this have any side effects? I specifically want to prevent any form of masking if I do this for a large number of packages. The only purpose of this is to speed up the process when the library()
function is called, or when mypackage::somefunction
is used.
Solution
It doesn't have a direct side-effect on the search path or global environment (which I think is what you are worried about). However, it will load dependent packages and run .onLoad
which can in theory have side-effects (it should not, but in theory bad package authors could mess with your environment).