View source: R/getSourceData.R
getSourceData | R Documentation |
Get parse information and source code from an R script file.
getSourceData(file, encoding, keep.source = getOption("keep.source"))
file |
a connection object or a character. |
encoding |
encoding to be assumed for input strings. |
keep.source |
a logical value; if |
The parse information of the script file is obtained using
getParseData
. The source code is read in using
readLines
. Arguments file
, encoding
and
keep.source
should be compatible with these functions.
Linters using results of this function may not work properly if the
encoding
argument does not match the encoding of the script
file.
A list of two elements:
parseData |
parse information data frame; |
Lines |
source code character vector of length the number of lines in the file. |
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.