Skip to content

Documentation request: how to compare environments? #127

Closed
@MichaelChirico

Description

@MichaelChirico

As part of testthat 3e migration for lintr (r-lib/lintr#910), I'm trying to replace this expect_equal() test comparing two environments whose content is identical:

https://github.com/r-lib/lintr/blob/aafba478622c6f43c3fb329c69945c36a4d94b68/tests/testthat/test-cache.R#L164

With <3e, it dispatches to all.equal() and voila.

With the stricter tests in waldo::compare(), however, it's not so simple.

I was unable in a brief search to determine what one should do to compare environments themselves:

  • there's no compare_proxy.environment
  • ?waldo::compare only mentions environments as regards ignore_formula_env and ignore_function_env (not really relevant here)
  • expect_equal(e1, e2, ignore_attr=TRUE) doesn't work, which seems to partially contradict ?waldo::compare ("For backward compatibility with all.equal(), you can also use TRUE..." -- which suggests we will get equivalent behavior to the old expect_equal() by setting ignore_attr=TRUE)
  • no mention of environments on the landing page: https://waldo.r-lib.org/
  • no vignettes

So I'm left wondering what's the recommended approach here.

The simplest fix is expect_identical(as.list(e1), as.list(e2)), but it does feel a bit hacky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions