Skip to content

skip_if_not_r_version()? #2022

Closed
Closed

Description

@MichaelChirico

This is #773 reborn, in a way.

Yes, skip_if_not(getRversion() >= "4.2.0") is pretty straightforward if you know about getRversion() and that there's a coercion method for strings that makes this work (quite infamously recently we found many people doing getRversion() >= 4.2 & subsequently booted from CRAN 😄).

But empirically, I have seen many different versions of equivalent skips. I think it's a common enough reason to skip tests that it warrants inclusion (alongside the similar skip_if_not_installed()). I have also seen a few packages implement similar helpers; centralizing that logic in {testthat} also makes sense to me. E.g. here's {lintr}'s version:

https://github.com/r-lib/lintr/blob/4de229f55e9387379beb42f61c235266bbc68dcd/tests/testthat/helper.R#L55-L59

Here are some other similar helpers:

https://github.com/cran/prt/blob/42ab58a2e712350735bd9eb54c6ff092e3192356/tests/testthat/helper-functions.R#L17-L21
https://github.com/cran/duckdb/blob/8bd532e6576edb85df225f3b7335ef90c17e92d0/tests/testthat/test-backend-dbplyr__duckdb_connection.R#L1-L5

Here are hits for a few iterations of ways this is done:

Even allowing that using getRversion() is common enough & the "correct" way, a dedicated skip_if_not_r_version() also allows making a neater message in the test logs.

c.f.

testthat::skip_if_not(getRversion() >= '6.6.6')
# Error: Reason: getRversion() >= "6.6.6" is not TRUE

lintr::skip_if_not_r_version('6.6.6')
# Error: Reason: R version at least 6.6.6 is required

Activity

  1. added
    feature
    on Jul 16, 2025
  2. hadley commented on Jul 16, 2025

    @hadley
    Member

    I'm open to this, but I'd like to figure out a better name, ideally something that's a bit shorter and conveys >=.

  3. MichaelChirico commented on Jul 16, 2025

    @MichaelChirico
    ContributorAuthor

    skip_for_r_before("4.1.0")?

    I also threw it to the LLMs:

    • Gemini
      • skip_if_r_below
      • skip_unless_r_version
      • skip_if_min_r
      • skip_on_r_older_than
    • ChatGPT
      • skip_if_r_version_below
      • skip_if_r_version_lt
      • skip_r_before
      • skip_unless_r
      • skip_if_old_r
    • Claude
      • skip_if_r_below
      • skip_if_r_lt
      • skip_before_r
      • skip_r_below
      • skip_if_old_r
  4. hadley commented on Jul 16, 2025

    @hadley
    Member

    I kind of like skip_unless_r("4.2.0")

  5. MichaelChirico commented on Jul 16, 2025

    @MichaelChirico
    ContributorAuthor

    Hm, that's among the ones I don't like, since it reads like it only works on one R version instead of a range.

  6. MichaelChirico commented on Jul 16, 2025

    @MichaelChirico
    ContributorAuthor

    Another option that might require a {backports} dependency would be something like

    skip_unless_r_has("|>") # or skip_if_r_lacks("|>")
    skip_unless_r_has("deparse1")

    That requires us to do some maintenance on the backend for interpreting strings like that, but it is pretty transparent to the reader about the nature of the skip. The other downside besides the highly manual implementation is that it's less clear when we can remove those skips over time (whereas when I do, say, update R>=4.1.0 to R>=4.2.0, I can just regex search for 4[.][12][.]0 instead of having to remember specific associated features).

  7. hadley commented on Jul 16, 2025

    @hadley
    Member

    Based on an initial misreading of your suggestion what about skip_r_unless(">= 4.2.0")

    I do in principle like the idea of requiring specific functions, but sometimes it's an arg that's important, and I agree that it gets harder to maintain because you can't easily tell when to remove it.

  8. MichaelChirico commented on Jul 16, 2025

    @MichaelChirico
    ContributorAuthor

    skip_unless_r(">= 4.2.0") sounds preferable to skip_r_unless(">= 4.2.0") to me. Would any operator besides ">=" be supported (or even needed)? I guess that's just like gt except by putting it in the string, we can use the non-syntactic symbol and not rely on user inferring gt-->greater than

  9. hadley commented on Jul 16, 2025

    @hadley
    Member

    Oh yeah, skip_unless_r() is definitely better, and I think we could fairly easily support all the operators, just for completeness.

  10. added a commit that references this issue on Jul 24, 2025
    c7fedf4
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

    featureskip

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions