The R Project SVN R

Rev

Rev 61433 | Rev 73574 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/utils/man/getFromNamespace.Rd
2
% Part of the R package, http://www.R-project.org
61678 ripley 3
% Copyright 1995-2013 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{getFromNamespace}
27481 ripley 7
\alias{assignInNamespace}
57694 ripley 8
\alias{assignInMyNamespace}
56186 murdoch 9
\alias{getFromNamespace}
27442 ripley 10
\alias{fixInNamespace}
11
\title{Utility functions for Developing Namespaces}
12
\description{
13
  Utility functions to access and replace the non-exported functions in
56382 murdoch 14
  a namespace, for use in developing packages with namespaces.
57118 ripley 15
 
61678 ripley 16
  They should not be used in production code (except perhaps
17
  \code{assignInMyNamespace}, but see the \sQuote{Note}).
27442 ripley 18
}
19
\usage{
20
getFromNamespace(x, ns, pos = -1, envir = as.environment(pos))
44243 ripley 21
 
22
assignInNamespace(x, value, ns, pos = -1,
23
                  envir = as.environment(pos))
24
 
57694 ripley 25
assignInMyNamespace(x, value)
26
 
27442 ripley 27
fixInNamespace(x, ns, pos = -1, envir = as.environment(pos), \dots)
28
}
29
\arguments{
30
  \item{x}{an object name (given as a character string).}
27508 ripley 31
  \item{value}{an \R object.}
56382 murdoch 32
  \item{ns}{a namespace, or character string giving the namespace.}
27442 ripley 33
  \item{pos}{where to look for the object: see \code{\link{get}}.}
34
  \item{envir}{an alternative way to specify an environment to look in.}
35
  \item{\dots}{arguments to pass to the editor: see \code{\link{edit}}.}
36
}
37
\details{
57694 ripley 38
  \code{assignInMyNamespace} is intended to be called from functions
39
  within a package, and chooses the namespace as the environment of the
40
  function calling it.
61433 ripley 41
 
56382 murdoch 42
  The namespace can be specified in several ways.  Using, for example,
61678 ripley 43
  \code{ns = "stats"} is the most direct, but a loaded package can be
44
  specified via any of the methods used for \code{\link{get}}: \code{ns}
45
  can also be the environment printed as \code{<namespace:foo>}.
27442 ripley 46
 
27930 ripley 47
  \code{getFromNamespace} is similar to (but predates) the
61678 ripley 48
  \code{\link{:::}} operator: it is more flexible in how the namespace
27930 ripley 49
  is specified.
61433 ripley 50
 
27442 ripley 51
  \code{fixInNamespace} invokes \code{\link{edit}} on the object named
52
  \code{x} and assigns the revised object in place of the original
53
  object.  For compatibility with \code{fix}, \code{x} can be unquoted.
54
}
57118 ripley 55
\section{Warning}{
56
  \code{assignInNamespace} should not be used in final code, and will in
57
  future throw an error if called from a package.  Already certain uses
58
  are disallowed.
59
}
27442 ripley 60
\note{
61678 ripley 61
  \code{assignInNamespace}, \code{assignInMyNamespace} and
62
  \code{fixInNamespace} change the copy in the namespace, but not any
63
  copies already exported from the namespace, in particular an object of
64
  that name in the package (if already attached) and any copies already
65
  imported into other namespaces.  They are really intended to be used
66
  \emph{only} for objects which are not exported from the namespace.
67
  They do attempt to alter a copy registered as an S3 method if one is
68
  found.
40240 ripley 69
 
70
  They can only be used to change the values of objects in the
56382 murdoch 71
  namespace, not to create new objects.
27442 ripley 72
}
73
\value{
74
  \code{getFromNamespace} returns the object found (or gives an error).
75
 
57694 ripley 76
  \code{assignInNamespace}, \code{assignInMyNamespace} and
77
  \code{fixInNamespace} are invoked for their side effect of changing
78
  the object in the namespace.
27442 ripley 79
}
80
 
81
\seealso{
82
  \code{\link{get}}, \code{\link{fix}}, \code{\link{getS3method}}
83
}
27930 ripley 84
\examples{
85
getFromNamespace("findGeneric", "utils")
86
\dontrun{
27467 ripley 87
fixInNamespace("predict.ppr", "stats")
27930 ripley 88
stats:::predict.ppr
89
getS3method("predict", "ppr")
27442 ripley 90
## alternatively
27930 ripley 91
fixInNamespace("predict.ppr", pos = 3)
92
fixInNamespace("predict.ppr", pos = "package:stats")
27442 ripley 93
}}
94
\keyword{data}