Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Sep 4, 2024
1 parent fcfe748 commit 73c899e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 34 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# renv (development version)

* `renv::install()` now errs if an incompatible `type` argument is provided.

* `renv::checkout()` now also checks out the version of `renv` available
and associated with the requested snapshot date. (#1966)

Expand Down
31 changes: 11 additions & 20 deletions R/checkout.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,28 @@ checkout <- function(repos = NULL,
lockfile <- renv_lockfile_init(project)
lockfile$Packages <- records

if ("restore" %in% actions) {
if ("restore" %in% actions) local({

# install the requested packages
restore(lockfile = lockfile, clean = clean)

# re-generate the activate script
local({
# make sure we can find 'renv' on the library paths
path <- renv_namespace_path("renv")
renv_scope_libpaths(c(dirname(path), renv_libpaths_all()))

# make sure we can find 'renv' on the library paths
renv_scope_libpaths(the$library_path)

# invoke activate
args <- c("--vanilla", "-s", "-e", shQuote("renv::activate()"))
r(args)

})
# invoke activate
args <- c("--vanilla", "-s", "-e", shQuote("renv::activate()"))
r(args)

# update the renv lockfile record
# (note: it might not be available when running tests)
local({

renv <- renv_lockfile_records(lockfile)[["renv"]]
if (is.null(renv))
return()

renv <- renv_lockfile_records(lockfile)[["renv"]]
if (!is.null(renv)) {
renv_scope_options(renv.verbose = FALSE)
record(records = list(renv = renv), project = project)
}

})

}
})

# re-generate the lockfile if requested
if ("snapshot" %in% actions) {
Expand Down
1 change: 1 addition & 0 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ install <- function(packages = NULL,

# check for explicitly-provided type -- we handle this specially for PPM
if (!is.null(type)) {
type <- renv_pkgtype_check(type)
renv_scope_binding(the, "install_pkg_type", type)
renv_scope_options(pkgType = type)
}
Expand Down
29 changes: 29 additions & 0 deletions R/pkgtype.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

renv_pkgtype_check <- function(type) {

case(
type == "source" ~ renv_pkgtype_check_source(type),
type == "binary" ~ renv_pkgtype_check_binary(type),
~ abort(sprintf("unrecognized type '%s'", type))
)

}

renv_pkgtype_check_source <- function(type) {
type
}

renv_pkgtype_check_binary <- function(type) {

# if the user has requested installation of a binary package,
# and this edition of R was compiled with support for binary
# packages, then proceed
pkgtype <- .Platform$pkgType
if (grepl("\\bbinary\\b", pkgtype, perl = TRUE))
return(type)

# user has requested installation of binary packages, but their
# installation of R only supports source packages
abort("type 'binary' is not supported on this platform")

}
4 changes: 2 additions & 2 deletions R/vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ vendor <- function(version = "main", project = getwd()) {
# A vendored copy of renv was created at: %s
# The renv auto-loader was generated at: %s
#
# Please add `renv$initialize()` to your package's `.onLoad()`
# to ensure that renv is initialized on package load.
# Please add `renv$initialize(libname, pkgname)` to your package's
# `.onLoad()` to ensure that renv is initialized on package load.
#
")

Expand Down
9 changes: 0 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
# NOTE: needs to be visible to embedded instances of renv as well
the$envir_self <<- renv_envir_self()

# figure out where 'renv' was loaded from -- if tests are running
# and we're using devtools::load_all(), we might need to fall back
# to whatever version of renv is available on the library paths
load <- Sys.getenv("DEVTOOLS_LOAD", unset = NA)
the$library_path <<- if (identical(load, .packageName))
dirname(renv_package_find(.packageName))
else
libname

# make sure renv (and packages using renv!!!) use tempdir for storage
# when running tests, or R CMD check
if (checking() || testing()) {
Expand Down
4 changes: 2 additions & 2 deletions inst/resources/vendor/renv.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

renv <- new.env(parent = new.env())

renv$initialize <- function() {
renv$initialize <- function(libname, pkgname) {

# set up renv + imports environments
attr(renv, "name") <- "embedded:renv"
Expand All @@ -25,7 +25,7 @@ renv$initialize <- function() {
renv$the$metadata <- ..metadata..

# run our load / attach hooks so internal state is initialized
renv$renv_zzz_load()
renv$.onLoad(libname, pkgname)

# remove our initialize method when we're done
rm(list = "initialize", envir = renv)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_that("renv can be vendored into an R package", {
# make sure renv is initializes in .onLoad()
code <- heredoc('
.onLoad <- function(libname, pkgname) {
renv$initialize()
renv$initialize(libname, pkgname)
}
')

Expand Down

0 comments on commit 73c899e

Please sign in to comment.