r-lib/pkgload

Question regarding DEVTOOLS_LOAD

maelle opened this issue · 10 comments

In the docs I see "devtools sets the DEVTOOLS_LOAD environment variable to "true" to let you check whether the helpers are run during package loading." which makes it sound as if one could use the environment variable to change the behavior but I see

withr_with_envvar(c(NOT_CRAN = "true", DEVTOOLS_LOAD = "true"),

So actually one can only use the helpers argument of load_all() to choose not to load testthat helpers?

What actually needs the environment variable? https://github.com/search?l=R&q=DEVTOOLS_LOAD&type=code

It was added in r-lib/devtools#1391. I think the idea was to allow you to be able to query whether the helpers were run or not. I don't think any external code uses it, though maybe @lionel- has some personal code that does.

IIRC it was for vdiffr but I think I found a better way than DEVTOOLS_LOAD in the end.

my confusion comes from the fact that from what I understand

  • At the moment no code uses the environment variable
  • When it comes up in pkgload, it's set to TRUE via withr.

So is it useless? I could well be missing something. 🙂

Since testthat also uses pkgload to set up the test environment, I'm not sure you can actually use that envvar to branch out anything. So it might well be useless.

testthat does not use pkgload (by default) for test_check(), i.e. in R CMD check

devtools::load_all() fails to load rgl, because my .onLoad function does some tricky stuff to decide which DLL to load. I was hoping there was an easy way to detect I was in load_all() so I could still work, but DEVTOOLS_LOAD doesn't appear to be set. Is there some other test I can use?

I recently needed a way to detect that code is running during load_all() to disable a call to browser() in that case. It'd be nice to have an interface for this.

I think there is a way, it is pkgload::is_dev_package().

I think is_dev_package() informs about the past (was this package loaded using devtools) whereas this issue is about the present (are we in the midst of loading this package).