find_arguments: Functions to extract an the argument from an expression

Description Usage Arguments Details Value Examples

Description

Use these functions to find a particular argument in an expression.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
formula_arg(ex, ..., n = 1L, message = "")

data_arg(ex, ..., n = 1L, message = "")

matrix_arg(ex, ..., n = 1L, message = "")

vector_arg(ex, ..., n = 1L, message = "")

character_arg(ex, ..., n = 1L, message = "")

numeric_arg(ex, ..., n = 1L, message = "")

list_arg(ex, ..., n = 1L, message = "")

function_arg(ex, ..., n = 1L, message = "")

table_arg(ex, ..., n = 1L, message = "")

arg_number(ex, n = 1L, ..., message = "")

first_arg(ex, ..., message = "")

named_arg(ex, nm, ..., message = "")

Arguments

ex

the tidy expression to check

...

passif/failif/okif tests

n

an integer. If there's more than one matching argument, which one do you want.

message

a character string. If this is not empty (i.e. "") then a fail result will be generated if the argument isn't found. Default: empty.

nm

the name of an argument as a character string (or a regex).

Details

If the expression isn't a call, it still has a value. These functions return that value if it's a match to the type sought. If ex directly from for_checkr(), only the first expression is checked.

Value

the matching expression as a quosure that can be evaluated with eval_tidy().

Examples

1
2
3
4
5
6
7
8
code <- for_checkr(quote(lm(mpg ~ hp, data = mtcars)))
formula_arg(code)
data_arg(code,
  failif( ! "hp" %in% names(V),
          "The data should have a column named 'hp'."))
matrix_arg(code)
named_arg(code, "data", failif(EX == `mtcars`, "I didn't want mtcars."))
arg_number(code, 3)

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