diff --git a/R/data.R b/R/data.R index 5003c0c77..b7d44165f 100644 --- a/R/data.R +++ b/R/data.R @@ -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") diff --git a/R/release.R b/R/release.R index 1748b3544..6f2196245 100644 --- a/R/release.R +++ b/R/release.R @@ -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: diff --git a/R/upkeep.R b/R/upkeep.R index 84f88657a..6f93573c7 100644 --- a/R/upkeep.R +++ b/R/upkeep.R @@ -243,6 +243,7 @@ tidy_upkeep_checklist <- function(last_upkeep = last_upkeep_year(), ) } + minimum_r_version <- pkg_minimum_r_version() bullets <- c( bullets, "### To finish", @@ -250,7 +251,7 @@ tidy_upkeep_checklist <- function(last_upkeep = last_upkeep_year(), 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()`"), diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index f2f893aee..9edde202e 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -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) +})