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

Fix use_data() + use_standalone() by not allowing decreasing R dependency #2077

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
objs <- get_objs_from_dots(dots(...))

if (version < 3) {
use_dependency("R", "depends", "2.10")
use_dependency("R", "depends", "2.10", allow_decrease = FALSE)

Check warning on line 48 in R/data.R

View check run for this annotation

Codecov / codecov/patch

R/data.R#L48

Added line #L48 was not covered by tests
} else {
use_dependency("R", "depends", "3.5")
use_dependency("R", "depends", "3.5", allow_decrease = FALSE)
}
if (internal) {
use_directory("R")
Expand Down
25 changes: 16 additions & 9 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use_dependency <- function(package, type, min_version = NULL) {
use_dependency <- function(package, type, min_version = NULL, allow_decrease = TRUE) {
check_name(package)
check_name(type)
check_bool(allow_decrease)

if (package != "R") {
check_installed(package)
Expand Down Expand Up @@ -65,17 +66,23 @@ use_dependency <- function(package, type, min_version = NULL) {
} else if (delta == 0 && version_spec(version) != version_spec(existing_version)) {
if (version_spec(version) > version_spec(existing_version)) {
direction <- "Increasing"
} else {
} else if (allow_decrease) {
direction <- "Decreasing"
} else {
direction <- NULL
}

ui_bullets(c(
"v" = "{direction} {.pkg {package}} version to {.val {version}} in
DESCRIPTION."
))
desc$set_dep(package, type, version = version)
desc$write()
changed <- TRUE
if (!is.null(direction)) {
ui_bullets(c(
"v" = "{direction} {.pkg {package}} version to {.val {version}} in
DESCRIPTION."
))
desc$set_dep(package, type, version = version)
desc$write()
changed <- TRUE
} else {
changed <- FALSE
}

} else if (delta > 0) {
# moving from, e.g., Suggests to Imports
Expand Down
2 changes: 1 addition & 1 deletion R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use_testthat_impl <- function(edition = NULL, parallel = FALSE) {
if (is_package()) {
edition <- check_edition(edition)

use_dependency("testthat", "Suggests", paste0(edition, ".0.0"))
use_dependency("testthat", "Suggests", paste0(edition, ".0.0"), allow_decrease = FALSE)
proj_desc_field_update("Config/testthat/edition", as.character(edition), overwrite = TRUE)

if (parallel) {
Expand Down
2 changes: 1 addition & 1 deletion R/use_standalone.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use_standalone <- function(repo_spec, file = NULL, ref = NULL, host = NULL) {
ver <- import$ver
}
ui_silence(
use_package(import$pkg, min_version = ver)
use_dependency(import$pkg, "Imports", min_version = ver, allow_decrease = FALSE)
)
}

Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ test_that("use_package(type = 'Suggests') guidance w/o and w/ rlang", {
expect_snapshot(use_package("purrr", "Suggests"))
})

test_that("use_data() will not decrease R version if called internally.", {
create_local_package()
# Use a minimum R version
use_package("R", "Depends", "4.1")
use_dependency("R", "Depends", "3.6", allow_decrease = FALSE)
expect_equal(subset(proj_deps(), package == "R")$version, ">= 4.1")
})

# use_dev_package() -----------------------------------------------------------

test_that("use_dev_package() writes a remote", {
Expand Down
Loading