Skip to content

Commit 734bb0c

Browse files
committed
Be more conservative in omitting warning
1 parent f3bf2ef commit 734bb0c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

R/utilities.r

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,19 @@ with_ordered_restart <- function(expr, .call) {
628628
class_y <- class(y)[1]
629629

630630
restart <- FALSE
631+
warn <- TRUE
632+
two_ordered <- FALSE
631633

632634
if (is.ordered(x) || is.ordered(y)) {
633635
restart <- TRUE
634-
if (is.ordered(x)) {
636+
x_is_ordered <- is.ordered(x)
637+
y_is_ordered <- is.ordered(y)
638+
# Check whether vec_cast should emit warning
639+
two_ordered <- x_is_ordered && y_is_ordered
640+
if (x_is_ordered) {
635641
x <- factor(as.character(x), levels = levels(x))
636642
}
637-
if (is.ordered(y)) {
643+
if (y_is_ordered) {
638644
y <- factor(as.character(y), levels = levels(y))
639645
}
640646
} else if (is.character(x) || is.character(y)) {
@@ -668,8 +674,11 @@ with_ordered_restart <- function(expr, .call) {
668674
format_error_call(.call),
669675
")"
670676
)
671-
672-
if (inherits(cnd, "vctrs_error_ptype2")) {
677+
if (inherits(cnd, "vctrs_error_cast")) {
678+
# Should be FALSE when vec_ptype2 has seen two ordered factors
679+
warn <- attr(y, "warn") %||% TRUE
680+
}
681+
if (warn) {
673682
deprecate_soft0(
674683
"3.4.0",
675684
I(msg),
@@ -684,6 +693,8 @@ with_ordered_restart <- function(expr, .call) {
684693
# Recurse with factor methods and restart with the result
685694
if (inherits(cnd, "vctrs_error_ptype2")) {
686695
out <- vec_ptype2(x, y, x_arg = x_arg, y_arg = y_arg, call = call)
696+
# Set warn attribute to forward to vec_cast
697+
attr(out, "warn") <- !two_ordered
687698
restart <- "vctrs_restart_ptype2"
688699
} else if (inherits(cnd, "vctrs_error_cast")) {
689700
out <- vec_cast(x, y, x_arg = x_arg, to_arg = y_arg, call = call)

0 commit comments

Comments
 (0)