Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moodymudskipper/0cd0ac724d0af998a5b65f6e259d490e to your computer and use it in GitHub Desktop.
Save moodymudskipper/0cd0ac724d0af998a5b65f6e259d490e to your computer and use it in GitHub Desktop.
fake namespace
# define `makeNamespace` function
eval(body(loadNamespace)[[c(8, 4, 4)]])
ns <- makeNamespace("fake")
# define functions
ns$foo <- function() "foo!"
ns$bar <- function() "bar!"
# export some
namespaceExport(ns, "foo")
#> <environment: 0x0000000011af0248>
# `:::` works
fake:::foo()
#> [1] "foo!"
fake:::bar()
#> [1] "bar!"
# `::` works on unexported functions
fake::foo()
#> [1] "foo!"
fake::bar()
#> Error: 'bar' is not an exported object from 'namespace:fake'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment