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

Default to the project library, if it exists #1586

Closed
wants to merge 4 commits into from
Closed

Conversation

hadley
Copy link
Member

@hadley hadley commented Jul 24, 2023

No description provided.

@hadley hadley requested a review from kevinushey July 25, 2023 22:11
@hadley hadley marked this pull request as ready for review July 25, 2023 22:21
Copy link
Collaborator

@kevinushey kevinushey left a comment

Choose a reason for hiding this comment

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

I'm not sure if I agree with the change. In general, I think renv APIs should almost always use the current library paths, and rely on load() to set up the library paths when a particular project has been loaded.

@@ -63,8 +63,8 @@ test_that("multiple libraries can be used when snapshotting", {
lockfile <- snapshot(lockfile = NULL, library = libs, type = "all")
records <- renv_lockfile_records(lockfile)

expect_length(records, 2L)
expect_setequal(names(records), c("bread", "toast"))
expect_length(records, 17) # 2 + 15 base/recommended packages
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should change type above and just supply an explicit dependency list?

Comment on lines +4 to +5
* If `library` is unsupplied, renv functions default to using the project
library, if `project` is supplied and the project library exists.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This reads pretty awkwardly to me. Can we give a more concrete example of the consequences of this change, or where users might see a change in behavior?

Comment on lines 11 to +13
#' @param library The \R library to be used. When `NULL`, the active project
#' library will be used instead.
#' library will be used instead. If no project is active, will fall back
#' to the system library.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this could just be something like "When NULL, the current library paths will be used."? IIRC almost all places in renv just use the current library paths, with the assumption that load() would have set up the default library paths.


unique(c(library, .Library))
if (!is.null(project)) {
proj_lib <- renv_paths_library(project = project)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this is the desired behavior. Suppose I do something like:

setwd("~/test/project")
renv::install("rlang")

And ~/test/project does happen to have an renv library, but I haven't actually activated or loaded that project. IMHO, we should install into the current library paths, not the renv project library. That is, I think loading a project explicitly should be a pre-requisite to having renv::install() use the project library.

Copy link
Member Author

Choose a reason for hiding this comment

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

But this PR doesn't change that code — this only affects that behaviour when you explicitly supply a project. In that case, I think it's reasonable to say that you want to operate on that project, regardless of what project is currently loaded in the current session (if any).

i.e. if you do renv::install("rlang", project = "another-project") don't you want to install into use another-projects library?

But maybe only installing to that project's library if it exists is wrong — if you say you want to install into a given project, and that project doesn't have a library, it seems like it would be better to error?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think my concern is that project is usually going to be non-NULL internally, since we fall back to the current working directory when no project is active. For example:

> renv:::renv_project_resolve(NULL)
[1] "/Users/kevin"

And we use that pretty commonly when resolving the "active" project, e.g. we do that here:

https://github.com/rstudio/renv/pull/1586/files#diff-76ebee0a54b80584fcf1eff0cdf55ef6f17e47a6d80cb807b5939e8e50cac32cR128

I think my fears would be abated if we distinguished between the case where project was explicitly supplied by the user, versus we just used the default / current value.

Copy link
Collaborator

@kevinushey kevinushey Jul 26, 2023

Choose a reason for hiding this comment

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

Could we add some tests (with multiple renv projects) just to confirm the behavior we want here as well? I guess the matrix here is (project A x project B) / (loaded x unloaded) / (explicit project / implicit project).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah got it; so we generally need to do the library resolution before the project resolution. Let me see if it's possible to do this in a reliable way, and if not, I can give up on this PR.

@kevinushey kevinushey closed this Sep 5, 2023
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.

2 participants