getSourceData {roger} | R Documentation |
Get Parse Information and Source Code
Description
Get parse information and source code from an R script file.
Usage
getSourceData(file, encoding, keep.source = getOption("keep.source"))
Arguments
file |
a connection object or a character. |
encoding |
encoding to be assumed for input strings. |
keep.source |
a logical value; if |
Details
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.
Value
A list of two elements:
parseData |
parse information data frame; |
Lines |
source code character vector of length the number of lines in the file. |
Examples
## 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)
[Package roger version 1.5-1 Index]