removeSource {utils}R Documentation

Remove Stored Source from a Function

Description

When options("keep.source") is TRUE, a copy of the original source code to a function is stored with it. This function removes that copy.

Usage

removeSource(fn)

Arguments

fn

A function or another language object (fulfilling is.language or is.expression) from which to remove the source.

Details

This removes the "srcref" and related attributes.

Value

A copy of the fn object with the source removed.

See Also

srcref for a description of source reference records, deparse for a description of how functions are deparsed.

Examples

## to make this act independently of the global 'options()' setting:
op <- options(keep.source = TRUE)
fn <- function(x) {
  x + 1 # A comment, kept as part of the source
}
fn
f2 <- removeSource(fn)
f2
stopifnot(length(attributes(fn))  > 0,
          length(attributes(f2)) == 0)
## Source attribute of parse()d expressions:
E  <- parse(text ="a <- x^y  # power")  ; names(attributes(E))
E. <- removeSource(E)                   ; names(attributes(E.))
stopifnot(length(attributes(E ))  > 0,
          length(attributes(E.)) == 0)
options(op) # reset to previous state
stopifnot(is.null(names(attributes(E.))))

[Package utils version 3.5.0 Index]