
Last chance! 50% off unlimited learning
Sale ends in
Utility functions to access and replace the non-exported functions in a namespace, for use in developing packages with namespaces.
They should not be used in production code (except perhaps
assignInMyNamespace
, but see the ‘Note’).
getFromNamespace(x, ns, pos = -1, envir = as.environment(pos))assignInNamespace(x, value, ns, pos = -1,
envir = as.environment(pos))
assignInMyNamespace(x, value)
fixInNamespace(x, ns, pos = -1, envir = as.environment(pos), …)
an object name (given as a character string).
an R object.
a namespace, or character string giving the namespace.
where to look for the object: see get
.
an alternative way to specify an environment to look in.
arguments to pass to the editor: see edit
.
getFromNamespace
returns the object found (or gives an error).
assignInNamespace
, assignInMyNamespace
and
fixInNamespace
are invoked for their side effect of changing
the object in the namespace.
assignInNamespace
should not be used in final code, and will in
future throw an error if called from a package. Already certain uses
are disallowed.
assignInMyNamespace
is intended to be called from functions
within a package, and chooses the namespace as the environment of the
function calling it.
The namespace can be specified in several ways. Using, for example,
ns = "stats"
is the most direct, but a loaded package can be
specified via any of the methods used for get
: ns
can also be the environment printed as <namespace:foo>
.
getFromNamespace
is similar to (but predates) the
:::
operator: it is more flexible in how the namespace
is specified.
fixInNamespace
invokes edit
on the object named
x
and assigns the revised object in place of the original
object. For compatibility with fix
, x
can be unquoted.
# NOT RUN {
getFromNamespace("findGeneric", "utils")
# }
# NOT RUN {
fixInNamespace("predict.ppr", "stats")
stats:::predict.ppr
getS3method("predict", "ppr")
## alternatively
fixInNamespace("predict.ppr", pos = 3)
fixInNamespace("predict.ppr", pos = "package:stats")
# }
Run the code above in your browser using DataLab