The R Project SVN R

Rev

Rev 74621 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 74621 Rev 74629
Line 3... Line 3...
3
% Copyright 2014-2018 R Core Team
3
% Copyright 2014-2018 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{removeSource}
6
\name{removeSource}
7
\alias{removeSource}
7
\alias{removeSource}
8
\title{Remove Stored Source from a Function}
8
\title{Remove Stored Source from a Function or Language Object}
9
\description{
9
\description{
10
  When \code{options("keep.source")} is \code{TRUE}, a copy of the
10
  When \code{options("keep.source")} is \code{TRUE}, a copy of the
11
  original source code to a function is stored with it.  This function
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
12
  removes that copy.
14
  \code{removeSource()}.
13
}
15
}
14
\usage{
16
\usage{
15
removeSource(fn)
17
removeSource(fn)
16
}
18
}
17
\arguments{
19
\arguments{
18
  \item{fn}{
-
 
19
    A \code{\link{function}} or another language object
20
  \item{fn}{a \code{\link{function}} or another language object
20
    (fulfilling \code{\link{is.language}} or \code{\link{is.expression}})
21
    (fulfilling \code{\link{is.language}}) from which to remove the
21
    from which to remove the source.
22
    source.
22
  }
23
  }
23
}
24
}
24
\details{
25
\details{
25
  This removes the \code{"srcref"} and related attributes.
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.
26
}
29
}
27
\value{
30
\value{
28
  A copy of the \code{fn} object with the source removed.
31
  A copy of the \code{fn} object with the source removed.
29
}
32
}
30
\seealso{
33
\seealso{
-
 
34
  \code{\link{is.language}} about language objects.
-
 
35
 
31
  \code{\link{srcref}} for a description of source reference records,
36
  \code{\link{srcref}} for a description of source reference records,
32
  \code{\link{deparse}} for a description of how functions are deparsed.
37
  \code{\link{deparse}} for a description of how functions are deparsed.
33
}
38
}
34
\examples{
39
\examples{
35
## to make this act independently of the global 'options()' setting:
40
## to make this act independently of the global 'options()' setting:
Line 44... Line 49...
44
f2
49
f2
45
stopifnot(length(attributes(fn)) > 0,
50
stopifnot(length(attributes(fn)) > 0,
46
          is.null(attributes(f2)),
51
          is.null(attributes(f2)),
47
          is.null(attributes(body(f2))))
52
          is.null(attributes(body(f2))))
48
 
53
 
-
 
54
## Source attribute of parse()d expressions,
49
## Source attribute of parse()d expressions: have {"srcref", "srcfile", "wholeSrcref"}
55
##	  have {"srcref", "srcfile", "wholeSrcref"} :
50
E  <- parse(text ="a <- x^y  # power")  ; names(attributes(E ))
56
E  <- parse(text ="a <- x^y  # power")  ; names(attributes(E ))
51
E. <- removeSource(E)                   ; names(attributes(E.))
57
E. <- removeSource(E)                   ; names(attributes(E.))
52
stopifnot(length(attributes(E ))  > 0,
58
stopifnot(length(attributes(E ))  > 0,
53
          is.null(attributes(E.)))
59
          is.null(attributes(E.)))
54
options(op) # reset to previous state
60
options(op) # reset to previous state
55
}
61
}
56
\keyword{ utility }
62
\keyword{utility}