Skip to content

Comparing named vectors, ignoring order (again) #863

Closed

Description

@wch

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.

Activity

  1. hadley commented on Apr 11, 2019

    @hadley
    Member

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

  2. kevinushey commented on Apr 11, 2019

    @kevinushey
    Collaborator

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

  3. wch commented on Apr 11, 2019

    @wch
    MemberAuthor

    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.

  4. added a commit that references this issue on Feb 15, 2024
    d1fd7d9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions