Skip to content

Commit 39de8d1

Browse files
authored
Ensure that quasi_label() doesn't error for missing inputs (#2248)
1 parent 325995d commit 39de8d1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

R/quasi-label.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ quasi_label <- function(quo, label = NULL, arg = NULL) {
5959
}
6060

6161
labelled_value <- function(value, label) {
62-
list(
63-
val = value,
64-
lab = label
65-
)
62+
if (missing(value)) {
63+
list(val = missing_arg(), lab = label)
64+
} else {
65+
list(val = value, lab = label)
66+
}
6667
}
6768

6869
quasi_capture <- function(.quo, .label, .capture, ...) {

tests/testthat/_snaps/quasi-label.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# missing arguments are propagated
2+
3+
Code
4+
expect_null(x$missing)
5+
Condition
6+
Error:
7+
! Expected `x$missing` to be NULL.
8+
Differences:
9+
`actual` is absent
10+
`expected` is NULL
11+
112
# produces useful summaries for long calls
213

314
Code

tests/testthat/test-quasi-label.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ test_that("symbols are quoted", {
1010
expect_equal(expr_label(quote(a)), "`a`")
1111
})
1212

13+
test_that("missing arguments are propagated", {
14+
x <- list(missing = missing_arg())
15+
expect_snapshot_failure(expect_null(x$missing))
16+
})
1317

1418
test_that("is_call_infix() handles complex calls (#1472)", {
1519
expect_false(is_call_infix(quote(

0 commit comments

Comments
 (0)