Skip to content

Comparison operators will not work with language objects in R-devel #5977

Description

@TysonStanley

Got a message today from Luke Tierney about this change in R-devel.

Comparison operators == and != can be used on language objects
(i.e. call objects and symbols). The == operator in particular often
seems to be used as a shorthand for calling identical(). The current
implementation involves comparing deparsed calls as strings. This has
a number of drawbacks and we would like to transition to a more robust
and efficient implementation. As a first step, R-devel will soon be
modified to signal an error when the ordered comparison operators <,
<=, >, >= are used on language objects. A small number of CRAN and
BIOC packages will fail after this change. If you want to check your
packages or code before the change is committed you can run the
current R-devel with the environment variable setting

_R_COMPARE_LANG_OBJECTS=eqonly

where using such a comparison now produces

quote(x + y) > 1
Error in quote(x + y) > 1 :
  comparison (>) is not possible for language types

I haven't done a thorough review of where/if this occurs yet. Plant to do that this weekend unless someone beats me to it.

Activity

  1. jangorecki commented on Mar 5, 2024

    @jangorecki
    Member

    What are the other values a accepted in _R_COMPARE_LANG_OBJECTS ?
    Sounds that we should add something like _R_COMPARE_LANG_OBJECTS=all to CI

  2. MichaelChirico commented on Mar 7, 2024

    @MichaelChirico
    Member

    Did the e-mail mention what the long-term state will be for comparison of language objects? I see ordered comparisons will be blocked, but are == and != slated for blocking as well?

  3. MichaelChirico commented on Mar 7, 2024

    @MichaelChirico
    Member

    I used the GitHub Code space on master (which runs R-devel) to check if we'll be affected, which we will:

    Running test id 580          Test 580 didn't produce the correct error:
    Expected: simply wrap with which(), and take the which() outside the loop if possible for efficiency
    Observed: comparison (<) is not possible for language types
    
  4. MichaelChirico commented on Mar 7, 2024

    @MichaelChirico
    Member

    Nice, actually this caught a bad test in our suite :) PR incoming

  5. MichaelChirico commented on Mar 7, 2024

    @MichaelChirico
    Member

    What are the other values a accepted in _R_COMPARE_LANG_OBJECTS ? Sounds that we should add something like _R_COMPARE_LANG_OBJECTS=all to CI

    Seems they're enumerated here. I don't know the corresponding behaviors.

    https://github.com/r-devel/r-svn/blob/31dc4569fe30653b20e8166576d967d486d41a73/src/main/relop.c#L117-L131

  6. MichaelChirico commented on Mar 7, 2024

    @MichaelChirico
    Member

    All of _R_COMPARE_LANG_OBJECTS={identical,error_calls,error} throw a ton of errors for us, since things like quote(.) == "..." are blocked, and we use that a lot.

    I am not sure yet what the intended migration path is -- using quote(.) == quote(.) instead? Would be good to have some guidance here before proceeding with a big fix.

    We'll probably have to deprecate %chin% behavior here which we've used for convenience: quote(x) %chin% c('a', 'b', 'c') works.

  7. MichaelChirico commented on Mar 7, 2024

    @MichaelChirico
    Member

    I think we should include #5986 as part of the next patch release.

  8. added this to the 1.15.4 milestone on Mar 7, 2024
  9. TysonStanley commented on Mar 7, 2024

    @TysonStanley
    MemberAuthor

    Agreed. The test is an easy fix but curious for the others. Not entirely sure why this would be an important change for R-devel unless they have a good workaround (e.g., quote(.) == quote(.))

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions