You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 TRUElintr::skip_if_not_r_version('6.6.6')
# Error: Reason: R version at least 6.6.6 is required
The text was updated successfully, but these errors were encountered:
This is #773 reborn, in a way.
Yes,
skip_if_not(getRversion() >= "4.2.0")
is pretty straightforward if you know aboutgetRversion()
and that there's a coercion method for strings that makes this work (quite infamously recently we found many people doinggetRversion() >= 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:
getRversion()
. But also notice hits likeskip_if(grepl("...", getRversion()))
: https://github.com/search?q=org%3Acran%20path%3Atestthat%20%2Fskip.*getRversion%2F&type=codeR.version()
. Messy. 42 hits. https://github.com/search?q=org%3Acran+path%3Atestthat+%2Fskip.*R%5C.Version%2F&type=codeskip_if_not_installed()
on a default package, e.g.skip_if_not_installed("base", "4.0.0")
: 42 hits. Esoteric. https://github.com/search?q=org%3Acran+path%3Atestthat+%2Fskip_if_not_installed%5C%28%5Cs*%5B%22%27%5D%28base%7Cutils%7Ctools%7Cstats%7Cgraphics%7CgrDevices%7Cdatasets%7Cmethods%29%2F&type=codeEven allowing that using
getRversion()
is common enough & the "correct" way, a dedicatedskip_if_not_r_version()
also allows making a neater message in the test logs.c.f.
The text was updated successfully, but these errors were encountered: