# NOT RUN {
## 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
names(attributes(fn)) # "srcref" (only)
names(attributes(body(fn))) # "srcref" "srcfile" "wholeSrcref"
f2 <- removeSource(fn)
f2
stopifnot(length(attributes(fn)) > 0,
is.null(attributes(f2)),
is.null(attributes(body(f2))))
## Source attribute of parse()d expressions,
## have {"srcref", "srcfile", "wholeSrcref"} :
E <- parse(text ="a <- x^y # power") ; names(attributes(E ))
E. <- removeSource(E) ; names(attributes(E.))
stopifnot(length(attributes(E )) > 0,
is.null(attributes(E.)))
options(op) # reset to previous state
# }
Run the code above in your browser using DataLab