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

Comparing named vectors, ignoring order (again) #863

Closed
wch opened this issue Apr 11, 2019 · 3 comments
Closed

Comparing named vectors, ignoring order (again) #863

wch opened this issue Apr 11, 2019 · 3 comments

Comments

@wch
Copy link
Member

@wch wch commented Apr 11, 2019

This is the same as #473. That previous issue was indirectly considered resolved by the implementation expect_setequal, but that's not what I had in mind. expect_setequal tests that two sortable vectors have the same contents, but what I had in mind was that two named vectors (including lists, which aren't generally sortable) would be tested to have the same key-value pairs.

The idea is that a and b below would be considered to be equivalent:

a <- list(x="a", y=2)
b <- list(y=2, x="a")

But these would not:

a <- list(x="a", y=2)
c <- list(x="a", z=2)

It was closed before because @hadley thought that doing it well would require quite a bit of code, but I don't think that's necessarily true -- I had a basic implementation of it in the previous issue.

@hadley
Copy link
Member

@hadley hadley commented Apr 11, 2019

I'd definitely consider a PR if you can figure out a good name for it.

@kevinushey
Copy link
Collaborator

@kevinushey kevinushey commented Apr 11, 2019

expect_same_members()? expect_mapequal()? (since we're sort of treating the list like a map in this case)

@wch
Copy link
Member Author

@wch wch commented Apr 11, 2019

I like expect_mapequal(). Although there is the odd case where a named vector has multiple entries with the same name. I'm not sure how we want to handle that.

@hadley hadley closed this in d1fd7d9 Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants