Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for joining ordered factors? #6852

Closed
gklarenberg opened this issue May 18, 2023 · 1 comment
Closed

Improve error message for joining ordered factors? #6852

gklarenberg opened this issue May 18, 2023 · 1 comment

Comments

@gklarenberg
Copy link

Would it be possible to improve the error message that is displayed when one is trying to join ordered factors (ordinal data) with different levels?

> df1 <- data.frame(D.1 = c(1,3,4,2,5),
+                  D.2 = factor(c(4,5,3,1,2), ordered = TRUE),
+                  F.4 = c(5,4,3,2,1))
> df1$D.2
[1] 4 5 3 1 2
Levels: 1 < 2 < 3 < 4 < 5
> 
> df2 <- data.frame(D.1 = c(6,2,3,4,1),
+                   D.2 = factor(c(NA,3,3,5,1), 
+                                exclude = NULL,
+                                ordered = TRUE,
+                                levels = c(1,2,3,4,5,NA)))
> df2$D.2
[1] <NA> 3    3    5    1   
Levels: 1 < 2 < 3 < 4 < 5 < <NA>
> 
> df3 <- full_join(df1, df2)
Joining with `by = join_by(D.1, D.2)`
Error in `full_join()`:
! Can't join `x$D.2` with `y$D.2` due to incompatible types.
ℹ `x$D.2` is a <ordered<cd34a>>.
ℹ `y$D.2` is a <ordered<88c4b>>.
Run `rlang::last_trace()` to see where the error occurred.

Granted - I am not sure how common this is, but I ran into it when trying to join survey data (obtained with the qualtRics package by @juliasilge), where NA was added to the levels (when participants skip a question). The error message was really difficult to decipher ("incompatible types", just "types"?), I could not find anything online. Only when I started making a reprex for a qualtRics issue, I realized what the problem was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants