Make .onLoad()
more robust w.r.t. knitr
#254
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #253
This generated extensive discussion in Slack, which I'll summarize here.
The root cause is arguably an infelicity in R; specifically in
isNamespaceLoaded()
. These failures occur when glue is being loaded while knitr's namespace is "sort of" loaded. It's loaded enough forisNamespaceLoaded()
to returnTRUE
, but not loaded enough forknitr::knit_engines$set()
to succeed. It feels like this should never happen, yet that's what's causing these failures.We first really noticed this in stringr's CI for ubuntu-18.04 (devel), e.g. https://github.com/tidyverse/stringr/actions/runs/1725746423. But it has nothing to do with r-devel or CI, but rather it's seen when installing packages from source, in a particular order. The phenomenon has been seen with R 4.1 by a regular user (yihui/knitr#2087). It has been seen in CI with Windows and R 3.6 (https://github.com/tidyverse/stringr/runs/4417596611?check_suite_focus=true). And we've been able to replicate it now.
So why did stringr surface this problem? It seems to be the combination of two recent changes:
.onLoad()
in version 1.5.1 on 2021-11-30importFrom(glue,glue)
in its NAMESPACE in tidyverse/stringr@ad7fe11#diff-b6b6854a02ae177f8860f49654ff250c1554d021ae434b6efdbe99d00bdc6055 on 2021-04-18Nice summary from @gaborcsardi:
We have consensus that the specific fix in this PR is reasonable and the broader issue re:
isNamespaceLoaded()
has been raised on the r-devel mailing list (isNamespaceLoaded() while the namespace is loading).