| 54801 |
ripley |
1 |
% File src/library/utils/man/removeSource.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 74621 |
maechler |
3 |
% Copyright 2014-2018 R Core Team
|
| 54801 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
|
|
6 |
\name{removeSource}
|
| 56186 |
murdoch |
7 |
\alias{removeSource}
|
| 74629 |
maechler |
8 |
\title{Remove Stored Source from a Function or Language Object}
|
| 54801 |
ripley |
9 |
\description{
|
|
|
10 |
When \code{options("keep.source")} is \code{TRUE}, a copy of the
|
| 74629 |
maechler |
11 |
original source code to a function is stored with it. Similarly,
|
|
|
12 |
\code{\link{parse}()} may keep formatted source for an expression.
|
|
|
13 |
Such source reference attributes are removed from the object by
|
|
|
14 |
\code{removeSource()}.
|
| 54801 |
ripley |
15 |
}
|
|
|
16 |
\usage{
|
|
|
17 |
removeSource(fn)
|
|
|
18 |
}
|
|
|
19 |
\arguments{
|
| 74629 |
maechler |
20 |
\item{fn}{a \code{\link{function}} or another language object
|
|
|
21 |
(fulfilling \code{\link{is.language}}) from which to remove the
|
|
|
22 |
source.
|
| 54801 |
ripley |
23 |
}
|
|
|
24 |
}
|
|
|
25 |
\details{
|
| 74629 |
maechler |
26 |
This removes the \code{"srcref"} and related attributes, via
|
|
|
27 |
\emph{recursive} cleaning of \code{body(fn)} in the case of a function
|
|
|
28 |
or the recursive language parts, otherwise.
|
| 54801 |
ripley |
29 |
}
|
|
|
30 |
\value{
|
| 74621 |
maechler |
31 |
A copy of the \code{fn} object with the source removed.
|
| 54801 |
ripley |
32 |
}
|
|
|
33 |
\seealso{
|
| 74629 |
maechler |
34 |
\code{\link{is.language}} about language objects.
|
|
|
35 |
|
| 54801 |
ripley |
36 |
\code{\link{srcref}} for a description of source reference records,
|
|
|
37 |
\code{\link{deparse}} for a description of how functions are deparsed.
|
|
|
38 |
}
|
|
|
39 |
\examples{
|
| 74621 |
maechler |
40 |
## to make this act independently of the global 'options()' setting:
|
|
|
41 |
op <- options(keep.source = TRUE)
|
| 54801 |
ripley |
42 |
fn <- function(x) {
|
|
|
43 |
x + 1 # A comment, kept as part of the source
|
|
|
44 |
}
|
|
|
45 |
fn
|
| 74621 |
maechler |
46 |
names(attributes(fn)) # "srcref" (only)
|
|
|
47 |
names(attributes(body(fn))) # "srcref" "srcfile" "wholeSrcref"
|
|
|
48 |
f2 <- removeSource(fn)
|
|
|
49 |
f2
|
|
|
50 |
stopifnot(length(attributes(fn)) > 0,
|
|
|
51 |
is.null(attributes(f2)),
|
|
|
52 |
is.null(attributes(body(f2))))
|
|
|
53 |
|
| 74629 |
maechler |
54 |
## Source attribute of parse()d expressions,
|
|
|
55 |
## have {"srcref", "srcfile", "wholeSrcref"} :
|
| 74621 |
maechler |
56 |
E <- parse(text ="a <- x^y # power") ; names(attributes(E ))
|
|
|
57 |
E. <- removeSource(E) ; names(attributes(E.))
|
|
|
58 |
stopifnot(length(attributes(E )) > 0,
|
|
|
59 |
is.null(attributes(E.)))
|
|
|
60 |
options(op) # reset to previous state
|
| 54801 |
ripley |
61 |
}
|
| 86517 |
smeyer |
62 |
\keyword{utilities}
|