I noticed that some answers on SO contain the use of pkg::name
where name is typically a function.
What is the advantage of this over library(pkg); ... name()
or require(pkg); ... name()
? R help, (help("::")
) says
For a package pkg, pkg::name returns the value of the exported variable name in namespace pkg, ... The namespace will be loaded if it was not loaded before the call, but the package will not be attached to the search path.
Does this mean that the function is used without the additional memory loss of loading the entire package, (ie, is it equivalent to import <function> from <package>
) in python? Or is it simply a means of telling R use the function from this package when there may be ambiguities?
My question relates the use of ::
in an Rscript or directly in the console and so is not a duplicate of the linked question as the OP in that question is discussing the use of of functions from the stats4
package during a package development project. On the other hand, there appear to be answers within this post that shed some light on my question, however. Thanks for the link. (Note the following discussion on Meta: duplicates flag)