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

skip_if_not_r_version()? #2022

Open
MichaelChirico opened this issue Nov 7, 2024 · 0 comments
Open

skip_if_not_r_version()? #2022

MichaelChirico opened this issue Nov 7, 2024 · 0 comments

Comments

@MichaelChirico
Copy link
Contributor

MichaelChirico commented Nov 7, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant