Skip to content

Commit

Permalink
Never lower an R version requirement in use_data() (#2083)
Browse files Browse the repository at this point in the history
* Introduce failing test

* Use NA when there's no minimum version stated for R

* Never lower minimum R version via use_data()

* Don't attempt to pass NA to numeric_version()

Apparently this works only in R >= 4.2
  • Loading branch information
jennybc authored Nov 20, 2024
1 parent 50dcb10 commit 487688b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
10 changes: 6 additions & 4 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ use_data <- function(...,

objs <- get_objs_from_dots(dots(...))

if (version < 3) {
use_dependency("R", "depends", "2.10")
} else {
use_dependency("R", "depends", "3.5")
original_minimum_r_version <- pkg_minimum_r_version()
serialization_minimum_r_version <- if (version < 3) "2.10" else "3.5"
if (is.na(original_minimum_r_version) ||
original_minimum_r_version < serialization_minimum_r_version) {
use_dependency("R", "depends", serialization_minimum_r_version)
}

if (internal) {
use_directory("R")
paths <- path("R", "sysdata.rda")
Expand Down
7 changes: 4 additions & 3 deletions R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,11 @@ author_has_rstudio_email <- function() {
pkg_minimum_r_version <- function() {
deps <- proj_desc()$get_deps()
r_dep <- deps[deps$package == "R" & deps$type == "Depends", "version"]
if (length(r_dep) == 0) {
return(numeric_version("0"))
if (length(r_dep) > 0) {
numeric_version(gsub("[^0-9.]", "", r_dep))
} else {
NA_character_
}
numeric_version(gsub("[^0-9.]", "", r_dep))
}

# Borrowed from pak, but modified also retain user's non-cran repos:
Expand Down
3 changes: 2 additions & 1 deletion R/upkeep.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,15 @@ tidy_upkeep_checklist <- function(last_upkeep = last_upkeep_year(),
)
}

minimum_r_version <- pkg_minimum_r_version()
bullets <- c(
bullets,
"### To finish",
"",
todo("`usethis::use_mit_license()`", grepl("MIT", desc$get_field("License"))),
todo(
'`usethis::use_package("R", "Depends", "{tidy_minimum_r_version()}")`',
tidy_minimum_r_version() > pkg_minimum_r_version()
is.na(minimum_r_version) || tidy_minimum_r_version() > minimum_r_version
),
todo("`usethis::use_tidy_description()`"),
todo("`usethis::use_tidy_github_actions()`"),
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,14 @@ test_that("use_data_raw() does setup", {

expect_true(is_build_ignored("^data-raw$"))
})

test_that("use_data() does not decrease minimum version of R itself", {
create_local_package()

use_package("R", "depends", "4.1")
original_minimum_r_version <- pkg_minimum_r_version()

use_data(letters)

expect_true(pkg_minimum_r_version() >= original_minimum_r_version)
})

0 comments on commit 487688b

Please sign in to comment.