Skip to content

Always attach utils when loading data/ files#325

Open
MichaelChirico wants to merge 9 commits intor-lib:mainfrom
MichaelChirico:load-data-attach-utils
Open

Always attach utils when loading data/ files#325
MichaelChirico wants to merge 9 commits intor-lib:mainfrom
MichaelChirico:load-data-attach-utils

Conversation

@MichaelChirico
Copy link
Contributor

@MichaelChirico MichaelChirico commented Mar 2, 2026

Closes #324. Written initially by Gemini, touched up by me.

I could rewrite the test using {processx} only, if seen fit to avoid incurring the {callr} dependency.

I suspected simply import(utils) in the {pkgload} NAMESPACE would work, but it doesn't, not quite sure why.

}

# always attach, as utils::data does. evalq to hide library from R CMD check
evalq(library(utils))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has the side effect of editing the user's search path, of course, but I think "it's fine".

it might wind up looking comparable to instead set up a shim environment between lazydata_env and package:base that copies {utils} exports, avoiding the somewhat hacky parent.env() code below.

# sys.source() returns invisible() so it doesn't return the names of the
# objects it creates. We'll need to find them ourselves.
for (path in paths_r) {
old_objs <- ls(lazydata_env, all.names = TRUE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini went ahead and corrected that sys.source() returns NULL, thus the earlier code was not actually populating the names of the objects found.

Not sure the intended behavior; we could (a) just use the simpler approach where we ignore the names for .R files; (b) add a new regression test that the return value of load_data() is WAI; (c) do nothing

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

Successfully merging this pull request may close these issues.

data/ R files can assume utils is attached, but load_all() fails

1 participant