get_source_expressions {lintr} | R Documentation |
Parsed sourced file from a filename
Description
This object is given as input to each linter.
Usage
get_source_expressions(filename, lines = NULL)
Arguments
filename |
the file to be parsed. |
lines |
a character vector of lines.
If |
Details
The file is read using the encoding
setting.
This setting is found by taking the first valid result from the following locations
The
encoding
key from the usual lintr configuration settings.The
Encoding
field from a PackageDESCRIPTION
file in a parent directory.The
Encoding
field from an R Project.Rproj
file in a parent directory.-
"UTF-8"
as a fallback.
Value
A list
with three components:
- expressions
a
list
ofn+1
objects. The firstn
elements correspond to each expression infilename
, and consist of a list of 8 elements:filename
(character
) the name of the file.line
(integer
) the line in the file where this expression begins.column
(integer
) the column in the file where this expression begins.lines
(namedcharacter
) vector of all lines spanned by this expression, named with the corresponding line numbers.parsed_content
(data.frame
) as given byutils::getParseData()
for this expression.xml_parsed_content
(xml_document
) the XML parse tree of this expression as given byxmlparsedata::xml_parse_data()
.content
(character
) the same aslines
as a single string (not split across lines).xml_find_function_calls(function_names)
(function
) a function that returns allSYMBOL_FUNCTION_CALL
XML nodes fromxml_parsed_content
with specified function names.
The final element of
expressions
is a list corresponding to the full file consisting of 7 elements:filename
(character
) the name of this file.file_lines
(character
) thereadLines()
output for this file.content
(character
) for .R files, the same asfile_lines
; for .Rmd or .qmd scripts, this is the extracted R source code (as text).full_parsed_content
(data.frame
) as given byutils::getParseData()
for the full content.full_xml_parsed_content
(xml_document
) the XML parse tree of all expressions as given byxmlparsedata::xml_parse_data()
.terminal_newline
(logical
) records whetherfilename
has a terminal newline (as determined byreadLines()
producing a corresponding warning).xml_find_function_calls(function_names)
(function
) a function that returns allSYMBOL_FUNCTION_CALL
XML nodes fromfull_xml_parsed_content
with specified function names.
- error
A
Lint
object describing any parsing error.- lines
The
readLines()
output for this file.
Examples
tmp <- tempfile()
writeLines(c("x <- 1", "y <- x + 1"), tmp)
get_source_expressions(tmp)
unlink(tmp)