Gets the source IDs (row indices) corresponding to given token.
Usage
ids_with_token(source_expression, value, fun = `==`, source_file = NULL)
with_id(source_expression, id, source_file)
Arguments
- source_expression
A list of source expressions, the result of a call to
get_source_expressions()
, for the desired filename.- value
Character. String corresponding to the token to search for. For example:
"SYMBOL"
"FUNCTION"
"EQ_FORMALS"
"$"
"("
- fun
For additional flexibility, a function to search for in the
token
column ofparsed_content
. Typically==
or%in%
.- source_file
(DEPRECATED) Same as
source_expression
. Will be removed.- id
Integer. The index corresponding to the desired row of
parsed_content
.
Value
ids_with_token
: The indices of the parsed_content
data frame
entry of the list of source expressions. Indices correspond to the
rows where fun
evaluates to TRUE
for the value
in the token column.
with_id
: A data frame corresponding to the row(s) specified in id
.
Functions
with_id()
: Return the row of theparsed_content
entry of the[get_source_expressions]()
object. Typically used in conjunction withids_with_token
to iterate over rows containing desired tokens.
Examples
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
source_exprs <- get_source_expressions(tmp)
#> Warning: cannot open file '/tmp/RtmpAx0Ma8/file181350bffbbb': No such file or directory
#> Error in file(con, "r"): cannot open the connection
ids_with_token(source_exprs$expressions[[1L]], value = "SYMBOL")
#> Error in eval(expr, envir, enclos): object 'source_exprs' not found
with_id(source_exprs$expressions[[1L]], 2L)
#> Error in eval(expr, envir, enclos): object 'source_exprs' not found