0

I am seeing the use of "::" more in R (perhaps exclusively by Hadley Wickham packages), but I cannot find documentation specifying its exact use cases. Examples include:

packrat::init()

or

devtools::install_github("rstudio/packrat")
josiekre
  • 795
  • 1
  • 7
  • 19
  • This is definitely not exclusive to Hadley's packages. `::` is a way to access package functions without attaching (loading) the package, or to refer to a package function when more than one package is loaded that contain the same function name. – Rich Scriven Oct 15 '14 at 18:15
  • So in `devtools::install_github("rstudio/packrat")`, if that's the only function you plan on using from `devtools`, then it's a bit easier to write that and load the namespace rather than call `library(devtools); install_github("rstudio/packrat")` and load the whole package when you're only using one function one time – Rich Scriven Oct 15 '14 at 18:23
  • This is probably also useful http://stackoverflow.com/questions/4879377/r-masked-functions – Rich Scriven Oct 15 '14 at 18:26

1 Answers1

2

Try

 ?`::`

From R help:

For a package pkg, pkg::name returns the value of the exported variable name in namespace pkg, whereas pkg:::name returns the value of the internal variable name. The namespace will be loaded if it was not loaded before the call, but the package will not be attached to the search path.

Specifying a variable or package that does not exist is an error.

Note that pkg::name does not access the objects in the environment package:pkg (which does not exist until the package's namespace is attached): the latter may contain objects not exported from the namespace. It can access datasets made available by lazy-loading.

Fernando
  • 7,785
  • 6
  • 49
  • 81
  • Thanks. I couldn't figure out how to search the help files for the odd character combo. Duh-- quotes. – josiekre Oct 15 '14 at 18:23
  • Yes, i had the same problem back in the day, just use the backtick quotes. – Fernando Oct 15 '14 at 18:24
  • 1
    @josiekre Note that R's startup message, presented to you at the start of every single session, includes a reference to using the function `help()` to access the docs. `help("::")` would have worked, no need for obscure backtick tricks. – joran Oct 15 '14 at 19:03