Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of crazy loadNamespace3() shenanigans #272

Closed
maxheld83 opened this issue Jun 30, 2019 · 4 comments
Closed

get rid of crazy loadNamespace3() shenanigans #272

maxheld83 opened this issue Jun 30, 2019 · 4 comments
Labels

Comments

@maxheld83
Copy link
Owner

maxheld83 commented Jun 30, 2019

I'm currently, for the most part, not just suffixing another path to R_LIBS, or even use withr::with_lib(), but I run some loadNamespace3("foo") to pick and choose loaded development helpers.

That felt clever at the time, but is not working great.
It just adds incredibly complexity and bugs, so I should delete this for a simple R_LIBS=$R_LIBS:foo:bar or something like that asap.

The one advantage of this was the ability to pick and choose some of the (quite numerous) development helper packages, rather than putting them all on the library search path (achieved in #223).

This isolation was always quite limited, because I couldn't at some point down the call tree unload a dev helper anyway (described in #212).

@maxheld83
Copy link
Owner Author

maxheld83 commented Jun 30, 2019

This isn't a priority or anything, but I'd just really like to understand why loadNamespace() (and my loadNamespace3() wrappers) don't work.
I worry that I don't really understand something about the logic of loadNamespace().

For an example, here is a reprex:

# start this with a fresh R session
# these are the `imports` dependencies of devtools (just an example)
needed <- tools::package_dependencies(packages = "devtools", which = "Imports")$devtools
before <- loadedNamespaces()
loadNamespace("devtools")
after <- loadedNamespaces()
after[!after %in% before]  # clearly, this has loaded *something*.
needed[!needed %in% after]  # but not these! why?!?
[1] "git2r"     "httr"      "jsonlite"  "rcmdcheck"

This is probably what has tripped me up here so much, but I really don't understand why these don't loaded.

Can't figure out what's special about these, or even what they have in common.

Weirder still, I get the same behavior with library('devtools') so I'm clearly not getting something here.

@maxheld83
Copy link
Owner Author

maxheld83 commented Jun 30, 2019

ok, hypothesis: does loadNamespace() simply recursively load whatever is importFrom() in NAMESPACE?
Then, if some pkg (such as git2r) is never importFrom() by devtools (it isn't) and so on recursively (not sure), then it won't be loaded on loadNamespace().
I guess the name kind of gives that away 🤦‍♂.

That would explain this.

~~If that is so, is there a function that would recursively load what is Imports: in DESCRIPTION? ~~
(Guessing that would be just looping over the results of tools::package_dependencies(recursive = TRUE) and just loadNamespace()ing all of those.

@maxheld83
Copy link
Owner Author

this is one of my better self-owns.

Not only does my wrapping of loadNamespace() not work, but it also has (aside from the limitation in #212) no upside.
If in-dev pkg foo has a dependency zap-github, and zap-cran is used as a development helper, then we can just set R_LIBS=$R_LIBS:$R_LIBS_WORKFLOW:$R_LIBS_ACTION and be done, because then zap-github will take precedence over zap-cran.
With loadNamespace() this might break.
If, on the other hand zap-cran is never called by dev-pkg foo, then there's no harm in having it on the library search path.

@maxheld83
Copy link
Owner Author

and to make matters worse, loadNamespace() only persists for the duration of a session, so when some package opens a new rsession (I think some do that such as pkgdown in #247) then everything breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant