Skip to content

Commit 57ca2a9

Browse files
committed
Deprecate the size argument of if_else()
1 parent 7ac5b9b commit 57ca2a9

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

R/if-else.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#' @param ptype An optional prototype declaring the desired output type. If
2424
#' supplied, this overrides the common type of `true`, `false`, and `missing`.
2525
#'
26-
#' @param size An optional size declaring the desired output size. If supplied,
27-
#' this overrides the size of `condition`.
26+
#' @param size `r lifecycle::badge("deprecated")`
27+
#'
28+
#' Output size is always taken from `condition`.
2829
#'
2930
#' @return
3031
#' A vector with the same size as `condition` and the same type as the common
@@ -57,10 +58,14 @@ if_else <- function(
5758
missing = NULL,
5859
...,
5960
ptype = NULL,
60-
size = NULL
61+
size = deprecated()
6162
) {
6263
check_dots_empty0(...)
6364

65+
if (!is_missing(size)) {
66+
lifecycle::deprecate_warn("1.2.0", "if_else(size = )")
67+
}
68+
6469
# Assert early since we `!` the `condition`
6570
check_logical(condition)
6671

@@ -81,7 +86,6 @@ if_else <- function(
8186
default = missing,
8287
default_arg = "missing",
8388
ptype = ptype,
84-
size = size,
8589
call = current_env()
8690
)
8791
}

man/if_else.Rd

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/if-else.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666
! Can't convert from `false` <double> to <integer> due to loss of precision.
6767
* Locations: 1
6868

69-
# `size` overrides the `condition` size
69+
# `size` is deprecated
7070

7171
Code
72-
if_else(TRUE, 1, 2, size = 2)
72+
x <- if_else(c(TRUE, FALSE), 1, 2, size = 2)
7373
Condition
74-
Error in `if_else()`:
75-
! `condition` must have size 2, not size 1.
74+
Warning:
75+
The `size` argument of `if_else()` is deprecated as of dplyr 1.2.0.
7676

tests/testthat/test-if-else.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ test_that("`ptype` overrides the common type", {
103103
})
104104
})
105105

106-
test_that("`size` overrides the `condition` size", {
107-
expect_identical(if_else(c(TRUE, FALSE), 1, 2, size = 2), c(1, 2))
108-
109-
# Note that `condition` is used as the name in the error message
110-
expect_snapshot(error = TRUE, {
111-
if_else(TRUE, 1, 2, size = 2)
106+
test_that("`size` is deprecated", {
107+
expect_snapshot({
108+
x <- if_else(c(TRUE, FALSE), 1, 2, size = 2)
112109
})
110+
expect_identical(x, c(1, 2))
113111
})

0 commit comments

Comments
 (0)