Skip to content

Commit

Permalink
fix logic error checking autoload envvar (#1584)
Browse files Browse the repository at this point in the history
* fix logic error checking autoload envvar

* fixup for windows
  • Loading branch information
kevinushey authored Jul 24, 2023
1 parent ab1ff5f commit acc968a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# renv 1.1.0 (UNRELEASED)

* Fixed a logic error in reading `RENV_AUTOLOAD_ENABLED`. (#1580)

* `renv::restore()` no longer runs without prompting on load if the
library is empty (#1543).

Expand Down
2 changes: 1 addition & 1 deletion R/autoload.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ renv_autoload_impl <- function() {

# check if we're disabled
enabled <- Sys.getenv("RENV_AUTOLOAD_ENABLED", unset = "TRUE")
if (truthy(enabled))
if (!truthy(enabled))
return(FALSE)

# bail if load is already being called
Expand Down
4 changes: 2 additions & 2 deletions R/imbue.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ renv_imbue_impl <- function(project, version = NULL, force = FALSE) {

}

renv_imbue_self <- function(project) {
renv_imbue_self <- function(project, source = NULL) {

# construct source, target paths
# (check if 'renv' is loaded to handle embedded case)
source <- if ("renv" %in% loadedNamespaces()) {
source <- source %||% if ("renv" %in% loadedNamespaces()) {
renv_namespace_path("renv")
} else {
renv_package_find("renv")
Expand Down
10 changes: 7 additions & 3 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ renv_metadata_init <- function() {
return()

# renv doesn't appear to be embedded; initialize metadata
pkgpath <- renv_namespace_path("renv")
record <- renv_description_read(path = file.path(pkgpath, "DESCRIPTION"))
path <- renv_namespace_path("renv")
record <- renv_description_read(path = file.path(path, "DESCRIPTION"))
version <- renv_metadata_version_create(record)
the$metadata <- renv_metadata_create(embedded = FALSE, version = version)

the$metadata <- renv_metadata_create(
embedded = FALSE,
version = version
)

}
2 changes: 1 addition & 1 deletion R/r.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R <- function() {
bin <- R.home("bin")
bin <- normalizePath(R.home("bin"), winslash = "/")
exe <- if (renv_platform_windows()) "R.exe" else "R"
file.path(bin, exe)
}
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test-autoload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

test_that("autoload() works", {
skip_on_cran()

# TODO: Failed on Windows CI, but works locally?
skip_on_windows()

project <- renv_tests_scope()

# initialize renv project here
init()

# make sure we have renv installed for this test
libpaths <- the$libpaths[[".libPaths()"]]
source <- find.package("renv", lib.loc = libpaths)
renv_imbue_self(project, source = source)

# make sure autoloader is enabled in this scope
renv_scope_envvars(RENV_AUTOLOAD_ENABLED = "TRUE")

# make sure default library paths are visible to child process
renv_scope_envvars(
R_LIBS = paste(libpaths, collapse = .Platform$path.sep),
R_LIBS_USER = NULL,
R_LIBS_SITE = NULL
)

# move to sub-directory
dir.create("subdir")
renv_scope_wd("subdir")

# create a .Rprofile that calls renv::autoload()
profile <- renv_test_code({
renv::autoload()
})

renv_scope_envvars(R_PROFILE_USER = profile)

# launch R and see what library paths we got
output <- renv_system_exec(
command = R(),
args = c("-s", "-e", renv_shell_quote("writeLines(.libPaths())")),
action = "testing autoload"
)

expect_equal(output, .libPaths())

})
4 changes: 4 additions & 0 deletions tests/testthat/test-profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ test_that("renv/profile is read and used to select a profile", {

renv_scope_envvars(RENV_PROFILE = NULL)
init(profile = "testing")

# make sure we have renv installed for this test
libpaths <- the$libpaths[[".libPaths()"]]
source <- find.package("renv", lib.loc = libpaths)
renv_imbue_self(project)

# check that profile was written
Expand Down

0 comments on commit acc968a

Please sign in to comment.