-
Notifications
You must be signed in to change notification settings - Fork 155
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
Changes from all commits
b96704c
b4b302f
62a0be2
601666c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,11 +191,17 @@ renv_libpaths_restore <- function() { | |
# 'renv::restore(library = <...>)') | ||
# | ||
# https://github.com/rstudio/renv/issues/1544 | ||
renv_libpaths_resolve <- function(library) { | ||
|
||
if (is.null(library)) | ||
return(renv_libpaths_all()) | ||
renv_libpaths_resolve <- function(library = NULL, project = NULL) { | ||
if (!is.null(library)) { | ||
return(unique(c(library, .Library))) | ||
} | ||
|
||
unique(c(library, .Library)) | ||
if (!is.null(project)) { | ||
proj_lib <- renv_paths_library(project = project) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
And There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 i.e. if you do 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think my concern is that
And we use that pretty commonly when resolving the "active" project, e.g. we do that here: I think my fears would be abated if we distinguished between the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add some tests (with multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah got it; so we generally need to do the |
||
if (dir.exists(proj_lib)) { | ||
return(unique(c(proj_lib, .Library))) | ||
} | ||
} | ||
|
||
renv_libpaths_all() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
#' @param lockfile Path to a lockfile. When `NULL` (the default), the `renv.lock` located in the root of the current project will be used. | ||
#' | ||
#' @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. | ||
Comment on lines
11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this could just be something like "When |
||
#' | ||
#' @param prompt Boolean; prompt the user before taking any action? For backwards | ||
#' compatibility, `confirm` is accepted as an alias for `prompt`. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test_that("resolve library with multiple fallbacks", { | ||
|
||
path <- tempfile() | ||
|
||
expect_equal(renv_libpaths_resolve(), .libPaths()) | ||
expect_equal(renv_libpaths_resolve(path), c(path, .Library)) | ||
|
||
dir.create(renv_paths_library(project = path), recursive = TRUE) | ||
expect_equal( | ||
renv_libpaths_resolve(NULL, path), | ||
c(renv_paths_library(project = path), .Library) | ||
) | ||
|
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should change |
||
expect_contains(names(records), c("bread", "toast")) | ||
|
||
.libPaths(oldlibpaths) | ||
|
||
|
There was a problem hiding this comment.
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?