fix: isExported is always TRUE after devtools::load_all() (#347) - #356
Merged
Conversation
jayqi
approved these changes
Sep 1, 2026
FunctionReporter listed `ls("package:<pkg>")` after force-attaching the
package with `require()`. devtools::load_all() copies the entire namespace
into that attached environment, so every function looked exported.
Use `getNamespaceExports()` on the namespace the reporter already loads.
This also means pkgnet no longer attaches the package it is analyzing as
a side effect.
The Windows covr workaround unconditionally detached `package:<pkg>`,
which only worked because `require()` had attached it. Guard the detach
on the package actually being on the search path, and condition the
re-attach on the same flag.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
bburns632
force-pushed
the
fix/347-isexported-after-load-all
branch
from
September 1, 2026 04:29
a641f3b to
aa6a3cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #347.
The bug
FunctionReporterdetermined which functions were exported by force-attaching the package withrequire()and then listing the attached environment:suppressPackageStartupMessages({ require(self$pkg_name, lib.loc = .libPaths()[1], character.only = TRUE) }) exported_obj_names <- ls(sprintf("package:%s", self$pkg_name))devtools::load_all()copies the entire namespace into that attached environment (pkgload:::populate_pkg_env,export_all = TRUEby default), so afterload_all()every function looked exported.The fix
Read the namespace's own export metadata via
getNamespaceExports(), using the namespaceextract_nodesalready loads throughprivate$get_pkg_env(). Thanks @jayqi for pointing at the right function in the issue thread.Two knock-on effects worth calling out:
calculate_test_coverage()unconditionallydetachedpackage:<pkg>, which only worked becauserequire()had attached it. It is now guarded on the package actually being on the search path, and the re-attach is conditioned on the same flag.Why the test changes are needed
The existing
isExportedfixtures could not have caught this bug. The only unexported function across all the fake test packages carrying anisExportedfixture is milne's.classname— andls()hides dot-prefixed names by default, so it readFALSEboth before and after the fix. Every other fixture function is exported, soTRUEwas correct either way. The fixtures were vacuous for this code path.A real regression test needs two things the suite did not have:
inst/silversteinfits: its NAMESPACE exports onlyCarrots, leavingcouplet_1andcouplet_2unexported. It had noisExportedfixture, so nothing needed regenerating.load_all(). The bug only manifests through whatload_all()does to the attached environment, so it cannot be simulated without invoking it. HencepkgloadinSuggests, guarded withskip_if_not_installed("pkgload")so it degrades gracefully.The test asserts the precondition (
couplet_1is in the attached env afterload_all()) before asserting the fix, so it fails loudly rather than silently passing ifload_all()'s behavior ever changes.One implementation detail: the test calls
unloadNamespace("silverstein")first. An earlier test in the same file loads silverstein, andload_all()over an already-loaded namespace takes a::-patching path that errors on pkgload 1.3.4 against current rlang (env_unlock() is defunct as of rlang 1.1.5). Starting from an unloaded namespace avoids that path entirely, so the test works on both old and new pkgload instead of needing a version floor inSuggests.Verification
Against
inst/silversteinafterpkgload::load_all():couplet_1TRUE(wrong)FALSEcouplet_2TRUE(wrong)FALSECarrots$public_methods$initializeTRUETRUEThe new test was confirmed non-vacuous: against unmodified
R/FunctionReporter.Rit fails on exactly the twoisExportedassertions withactual: TRUE.Full local
devtools::test(): 252 pass, 2 fail. Both failures arecovr::package_coverage()errors on baseballstats (test-FunctionReporter-class.R:91,test-plotting.R:12). They are pre-existing and unrelated — I checked outmainand ran the full suite there, getting the identical two failures, and CI is green onmainat2cd9ea8(the commit this branches from). Local environment only; deferring to CI.🤖 Generated with Claude Code