## Keep parse data in non interactive sessions.
if (!interactive())
op <- options(keep.source = TRUE)
fil <- tempfile(fileext = ".R")
cat("## A simple function",
"foo <- function(x, y)",
"{",
" z <- x + y",
" if (z > 3)",
" (x * y)^2",
" else",
" sqrt(x * y)",
"}",
file = fil, sep = "\n")
getSourceData(fil)
Run the code above in your browser using DataLab