Skip to content

Commit

Permalink
closes #2047
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Dec 17, 2024
1 parent 412343d commit e3c5576
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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)

* `renv` now detects dependencies from usages of `utils::citation()`. (#2047)

* Fixed an issue where packages installed from r-universe via an explicit
URL remote could not be restored. (#2060)

Expand Down
22 changes: 21 additions & 1 deletion R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ renv_dependencies_discover_r <- function(path = NULL,
renv_dependencies_discover_r_library_require,
renv_dependencies_discover_r_require_namespace,
renv_dependencies_discover_r_colon,
renv_dependencies_discover_r_citation,
renv_dependencies_discover_r_pacman,
renv_dependencies_discover_r_modules,
renv_dependencies_discover_r_import,
Expand Down Expand Up @@ -1225,14 +1226,33 @@ renv_dependencies_discover_r_colon <- function(node, envir) {
if (is.symbol(package))
package <- as.character(package)

if (!is.character(package) || length(package) != 1)
if (!is.character(package) || length(package) != 1L)
return(FALSE)

envir[[package]] <- TRUE
TRUE

}

renv_dependencies_discover_r_citation <- function(node, envir) {

node <- renv_call_expect(node, "utils", "citation")
if (is.null(node))
return(FALSE)

matched <- catch(match.call(utils::citation, node))
if (inherits(matched, "error"))
return(FALSE)

package <- matched[["package"]]
if (!is.character(package) || length(package) != 1L)
return(FALSE)

envir[[package]] <- TRUE
TRUE

}

renv_dependencies_discover_r_pacman <- function(node, envir) {

node <- renv_call_expect(node, "pacman", "p_load")
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,10 @@ test_that("https://github.com/rstudio/renv/issues/2052", {
expect_contains(deps$Package, "A")

})

test_that("https://github.com/rstudio/renv/issues/2047", {
renv_tests_scope()
writeLines("citation(\"breakfast\")", con = "_deps.R")
init()
expect_true(renv_package_installed("breakfast"))
})

0 comments on commit e3c5576

Please sign in to comment.