| 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
encodingkey from the usual lintr configuration settings.The
Encodingfield from a PackageDESCRIPTIONfile in a parent directory.The
Encodingfield from an R Project.Rprojfile in a parent directory.-
"UTF-8"as a fallback.
Value
A list with three components:
- expressions
a
listofn+1objects. The firstnelements correspond to each expression infilename, and consist of a list of 9 elements:filename(character)line(integer) the line infilenamewhere this expression beginscolumn(integer) the column infilenamewhere this expression beginslines(namedcharacter) vector of all lines spanned by this expression, named with the line number corresponding tofilenameparsed_content(data.frame) as given byutils::getParseData()for this expressionxml_parsed_content(xml_document) the XML parse tree of this expression as given byxmlparsedata::xml_parse_data()content(character) the same aslinesas a single string (not split across lines)
The final element of
expressionsis a list corresponding to the full file consisting of 6 elements:filename(character)file_lines(character) thereadLines()output for this filecontent(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 contentfull_xml_parsed_content(xml_document) the XML parse tree of all expressions as given byxmlparsedata::xml_parse_data()terminal_newline(logical) records whetherfilenamehas a terminal newline (as determined byreadLines()producing a corresponding warning)
- error
A
Lintobject describing any parsing error.- lines
The
readLines()output for this file.
Examples
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
get_source_expressions(tmp)