line_calling: Find a line calling a function

Description Usage Arguments Details Value Examples

View source: R/line_calling.R

Description

Searches throughly through each line in a checkr_result to find a call to any of the functions listed in the dots. ...

Usage

1
2
line_calling(ex, ..., n = 1L, message = "Didn't find matching function.",
  just_the_fun = FALSE)

Arguments

ex

a checkr_result from a previous application of a checkr function, e.g. for_checkr()

...

unquoted functions to search for. A match to any one will trigger success.

n

an integer specifying which successful line to return. (Default: 1, the first.)

message

a character string to include in the checkr_result if the search is a failure.

just_the_fun

If TRUE, don't return the whole line, just the call involving the function

Details

The functions in ... should be unquoted, e.g. sin or lm rather than "sin". Note that infix functions, e.g. +, -, ||, must be in backquotes: `+`.

Like all checkr functions, if the input ex is marked as a fail the output will be a short circuit, that is, immediately returning the input unchanged.

Value

A checkr_result with a pass, fail, or ok result. If a pass, the code component of the returned value will have the line found by the search. Otherwise it will contain the input code unaltered.

Examples

1
2
3
4
5
code <- for_checkr("x <- 1; y <- x^2; z <- (y^2 + 7) / 2")
line_calling(code, `^`, message="Didn't find any line using exponentiation.")
line_calling(code, `^`, message="Didn't find any line using exponentiation.",
    just_the_fun = TRUE)
line_calling(code, `^`, n = 2L, message = "Didn't find a second line using exponentiation.")

dtkaplan/checkr2 documentation built on May 17, 2019, 4:01 p.m.