The first argument to every expect_ function can use unquoting to construct better labels. This makes it easy to create informative labels expectations are used inside a function or a for loop. quasi_label() wraps up the details, returning the expression and label.

quasi_label(quo, label = NULL, arg = "quo")



A quosure created by rlang::enquo().


An optional label to override the default. This is only provided for internal usage. Modern expectations should not include a label parameter.


Argument name shown in error message if quo is missing.


A list containing two elements:


The evaluate value of quo


The quasiquoted label generated from quo


Because all expect_ function use unquoting to generate more informative labels, you can not use unquoting for other purposes. Instead, you'll need to perform all other unquoting outside of the expectation and only test the results.


f <- function(i) if (i > 3) i * 9 else i * 10 i <- 10 # This short of expression commonly occurs inside a for loop or function # And the failure isn't helpful because you can't see the value of i # that caused the problem: show_failure(expect_equal(f(i), i * 10))
#> Failed expectation: #> f(i) not equal to i * 10. #> 1/1 mismatches #> [1] 90 - 100 == -10
# To overcome this issue, testthat allows you to unquote expressions using # !!. This causes the failure message to show the value rather than the # variable name show_failure(expect_equal(f(!!i), !!(i * 10)))
#> Failed expectation: #> f(10) not equal to 100. #> 1/1 mismatches #> [1] 90 - 100 == -10