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

Easy way to globally and permanently set testthat edition #1970

Closed
CGlemser opened this issue Jul 4, 2024 · 1 comment
Closed

Easy way to globally and permanently set testthat edition #1970

CGlemser opened this issue Jul 4, 2024 · 1 comment

Comments

@CGlemser
Copy link

CGlemser commented Jul 4, 2024

A colleague and I just had issues with different behaviours of testthat in the same package version and R version until we figured out that he had edition 2 active and I had edition 3 active, even though none of us had ever touched the testthat settings knowingly. We are now wondering if there is an easy way to globally and permanently set the testthat edition, e.g. via a function call in .Rprofile or an environment variable?

We are aware that we can set the edition in the DESCRIPTION file, however there are instances where we found the testthat functionality to be very useful and handy outside of the unit testing framework. We also tried putting testthat::local_edition(3) in the .Rprofile, but a) testthat might not always be installed e.g. after an R version update and b) this also triggered lots of messages on deferred events:

Setting global deferred event(s).
i These will be run:
  * Automatically, when the R session ends.
  * On demand, if you call `withr::deferred_run()`.
i Use `withr::deferred_clear()` to clear them without executing.

Our best solution currently is to put suppressMessages(try(testthat::local_edition(3))) in the .Rprofile, to avoid different editions in the future, but this feels very hacky to us. Is there an easier way to globally and permanently set the testthat edition?

@hadley
Copy link
Member

hadley commented Oct 22, 2024

I don't think you should be setting the edition outside of a given packages for exactly this reason — people will get different behaviours depending on which version they have set.

@hadley hadley closed this as completed Oct 22, 2024
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

2 participants