@@ -628,13 +628,19 @@ with_ordered_restart <- function(expr, .call) {
628
628
class_y <- class(y )[1 ]
629
629
630
630
restart <- FALSE
631
+ warn <- TRUE
632
+ two_ordered <- FALSE
631
633
632
634
if (is.ordered(x ) || is.ordered(y )) {
633
635
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 ) {
635
641
x <- factor (as.character(x ), levels = levels(x ))
636
642
}
637
- if (is.ordered( y ) ) {
643
+ if (y_is_ordered ) {
638
644
y <- factor (as.character(y ), levels = levels(y ))
639
645
}
640
646
} else if (is.character(x ) || is.character(y )) {
@@ -668,8 +674,11 @@ with_ordered_restart <- function(expr, .call) {
668
674
format_error_call(.call ),
669
675
" )"
670
676
)
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 ) {
673
682
deprecate_soft0(
674
683
" 3.4.0" ,
675
684
I(msg ),
@@ -684,6 +693,8 @@ with_ordered_restart <- function(expr, .call) {
684
693
# Recurse with factor methods and restart with the result
685
694
if (inherits(cnd , " vctrs_error_ptype2" )) {
686
695
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
687
698
restart <- " vctrs_restart_ptype2"
688
699
} else if (inherits(cnd , " vctrs_error_cast" )) {
689
700
out <- vec_cast(x , y , x_arg = x_arg , to_arg = y_arg , call = call )
0 commit comments