Skip to content

Easy way to globally and permanently set testthat edition #1970

@CGlemser

Description

@CGlemser

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions