From 161403b5036a1b93ad05ec6b61cf495a9bcf205a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 30 Jan 2026 17:13:42 -0600 Subject: [PATCH 1/5] Actually drop superseded usethis functions Fixes #2585 --- NAMESPACE | 6 -- NEWS.md | 1 + R/sitrep.R | 128 +++++++++++++++++--------------- R/test.R | 4 +- tests/testthat/_snaps/sitrep.md | 84 +++++++++++++++++++++ tests/testthat/test-sitrep.R | 57 ++++++++++++++ 6 files changed, 213 insertions(+), 67 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 46884560e..40d2f0e53 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -113,12 +113,6 @@ importFrom(remotes,update_packages) importFrom(sessioninfo,package_info) importFrom(sessioninfo,session_info) importFrom(stats,update) -importFrom(usethis,ui_code) -importFrom(usethis,ui_done) -importFrom(usethis,ui_field) -importFrom(usethis,ui_path) -importFrom(usethis,ui_todo) -importFrom(usethis,ui_value) importFrom(usethis,use_test) importFrom(utils,available.packages) importFrom(utils,contrib.url) diff --git a/NEWS.md b/NEWS.md index fe09318c6..6c7535ef8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * `build_vignettes()` and `clean_vignettes()` are now deprecated. We no longer recommend building vignettes in this way; instead use `pkgdown::build_article()` to render articles locally (#2488). * `build_site()` now just calls `pkgdown::build_site()`, meaning that you will get more (informative) output by default (#2578). * New `check_mac_devel()` function to check a package using the macOS builder at https://mac.r-project.org/macbuilder/submit.html (@nfrerebeau, #2507) +* `dev_sitrep()` now uses cli for user-facing messages instead of deprecated usethis UI functions. * `dev_sitrep()` now works correctly in Positron (#2618). * `is_loading()` is now re-exported from pkgload (#2556). * `load_all()` now errors if called recursively, i.e. if you accidentally include a `load_all()` call in one of your R source files (#2617). diff --git a/R/sitrep.R b/R/sitrep.R index d21dcef61..1d5eed6c6 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -66,7 +66,7 @@ check_for_rstudio_updates <- function( sprintf( "%s.\nDownload at: %s", result[["update-message"]], - ui_field(result[["update-url"]]) + result[["update-url"]] ) ) } @@ -93,7 +93,6 @@ r_release <- memoise::memoise(.r_release) #' everything should be ready for package development. #' #' @return A named list, with S3 class `dev_sitrep` (for printing purposes). -#' @importFrom usethis ui_code ui_field ui_todo ui_value ui_done ui_path #' @export #' @examples #' \dontrun{ @@ -104,21 +103,49 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) { has_build_tools <- !is_windows || pkgbuild::has_build_tools(debug = debug) + new_dev_sitrep( + pkg = pkg, + r_version = getRversion(), + r_path = path_real(R.home()), + r_release_version = r_release(), + has_build_tools = has_build_tools, + rtools_path = if (has_build_tools) pkgbuild::rtools_path(), + devtools_version = packageVersion("devtools"), + devtools_deps = remotes::package_deps("devtools", dependencies = NA), + pkg_deps = if (!is.null(pkg)) { + remotes::dev_package_deps(pkg$path, dependencies = TRUE) + }, + rstudio_version = if (is_rstudio_running()) rstudioapi::getVersion(), + rstudio_msg = if (!is_positron()) check_for_rstudio_updates() + ) +} + +new_dev_sitrep <- function( + pkg = NULL, + r_version = getRversion(), + r_path = path_real(R.home()), + r_release_version = r_version, + has_build_tools = TRUE, + rtools_path = NULL, + devtools_version = packageVersion("devtools"), + devtools_deps = data.frame(package = character(), diff = numeric()), + pkg_deps = NULL, + rstudio_version = NULL, + rstudio_msg = NULL +) { structure( list( pkg = pkg, - r_version = getRversion(), - r_path = path_real(R.home()), - r_release_version = r_release(), + r_version = r_version, + r_path = r_path, + r_release_version = r_release_version, has_build_tools = has_build_tools, - rtools_path = if (has_build_tools) pkgbuild::rtools_path(), - devtools_version = packageVersion("devtools"), - devtools_deps = remotes::package_deps("devtools", dependencies = NA), - pkg_deps = if (!is.null(pkg)) { - remotes::dev_package_deps(pkg$path, dependencies = TRUE) - }, - rstudio_version = if (is_rstudio_running()) rstudioapi::getVersion(), - rstudio_msg = if (!is_positron()) check_for_rstudio_updates() + rtools_path = rtools_path, + devtools_version = devtools_version, + devtools_deps = devtools_deps, + pkg_deps = pkg_deps, + rstudio_version = rstudio_version, + rstudio_msg = rstudio_msg ), class = "dev_sitrep" ) @@ -128,80 +155,68 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) { print.dev_sitrep <- function(x, ...) { all_ok <- TRUE - hd_line("R") + cli::cli_rule("R") kv_line("version", x$r_version) kv_line("path", x$r_path, path = TRUE) if (x$r_version < x$r_release_version) { - ui_todo( - ' - {ui_field("R")} is out of date ({ui_value(x$r_version)} vs {ui_value(x$r_release_version)}) - ' - ) + cli::cli_bullets(c( + "!" = "{.field R} is out of date ({.val {x$r_version}} vs {.val {x$r_release_version}})" + )) all_ok <- FALSE } if (is_windows) { - hd_line("Rtools") + cli::cli_rule("Rtools") if (x$has_build_tools) { kv_line("path", x$rtools_path, path = TRUE) } else { - ui_todo( - ' - {ui_field("RTools")} is not installed: - Download and install it from: {ui_field("https://cloud.r-project.org/bin/windows/Rtools/")} - ' - ) + cli::cli_bullets(c( + "!" = "{.field RTools} is not installed.", + " " = "Download and install it from: {.url https://cloud.r-project.org/bin/windows/Rtools/}" + )) } all_ok <- FALSE } if (!is.null(x$rstudio_version)) { - hd_line(if (is_positron()) "Positron" else "RStudio") + cli::cli_rule(if (is_positron()) "Positron" else "RStudio") kv_line("version", x$rstudio_version) if (!is.null(x$rstudio_msg)) { - ui_todo(x$rstudio_msg) + cli::cli_bullets(c("!" = "{x$rstudio_msg}")) all_ok <- FALSE } } - hd_line("devtools") + cli::cli_rule("devtools") kv_line("version", x$devtools_version) devtools_deps_old <- x$devtools_deps$diff < 0 if (any(devtools_deps_old)) { - ui_todo( - ' - {ui_field("devtools")} or its dependencies out of date: - {paste(ui_value(x$devtools_deps$package[devtools_deps_old]), collapse = ", ")} - Update them with {ui_code("devtools::update_packages(\\"devtools\\")")} - ' - ) + cli::cli_bullets(c( + "!" = "{.field devtools} or its dependencies out of date:", + " " = "{.val {x$devtools_deps$package[devtools_deps_old]}}", + " " = "Update them with {.code devtools::update_packages(\"devtools\")}" + )) all_ok <- FALSE } - hd_line("dev package") + cli::cli_rule("dev package") kv_line("package", x$pkg$package) kv_line("path", x$pkg$path, path = TRUE) pkg_deps_old <- x$pkg_deps$diff < 0 if (any(pkg_deps_old)) { - ui_todo( - ' - {ui_field(x$pkg$package)} dependencies out of date: - {paste(ui_value(x$pkg_deps$package[pkg_deps_old]), collapse = ", ")} - Update them with {ui_code("devtools::install_dev_deps()")} - ' - ) + cli::cli_bullets(c( + "!" = "{.field {x$pkg$package}} dependencies out of date:", + " " = "{.val {x$pkg_deps$package[pkg_deps_old]}}", + " " = "Update them with {.code devtools::install_dev_deps()}" + )) all_ok <- FALSE } if (all_ok) { - ui_done( - " - All checks passed - " - ) + cli::cli_bullets(c("v" = "All checks passed")) } invisible(x) @@ -210,19 +225,12 @@ print.dev_sitrep <- function(x, ...) { # Helpers ----------------------------------------------------------------- -hd_line <- function(name) { - cat_rule(cli::style_bold(name)) -} - kv_line <- function(key, value, path = FALSE) { if (is.null(value)) { - value <- cli::col_silver("") + cli::cli_inform(c("*" = "{key}: {.silver }")) + } else if (path) { + cli::cli_inform(c("*" = "{key}: {.path {value}}")) } else { - if (path) { - value <- ui_path(value, base = NA) - } else { - value <- ui_value(value) - } + cli::cli_inform(c("*" = "{key}: {.val {value}}")) } - cli::cat_line(cli::symbol$bullet, " ", key, ": ", value) } diff --git a/R/test.R b/R/test.R index 575a6ea40..9bc74731a 100644 --- a/R/test.R +++ b/R/test.R @@ -31,7 +31,9 @@ test <- function( if (!uses_testthat(pkg)) { cli::cli_inform(c(i = "No testing infrastructure found.")) if (!interactive()) { - ui_todo('Setup testing with {ui_code("usethis::use_testthat()")}.') + cli::cli_bullets(c( + "!" = 'Setup testing with {.code usethis::use_testthat()}.' + )) return(invisible()) } if (yesno("Create it?")) { diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index 817b7b734..3df66ab91 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -1,3 +1,87 @@ +# print shows all checks passed + + Code + print(x) + Message + -- R ----------------------------------- + * version: 4.4.0 + * path: '/usr/lib/R' + -- devtools ---------------------------- + * version: 2.4.6 + -- dev package ------------------------- + * package: + * path: + v All checks passed + +# print warns when R is out of date + + Code + print(x) + Message + -- R ----------------------------------- + * version: 4.3.0 + * path: '/usr/lib/R' + ! R is out of date (4.3.0 vs 4.4.0) + -- devtools ---------------------------- + * version: 2.4.6 + -- dev package ------------------------- + * package: + * path: + +# print warns about outdated devtools deps + + Code + print(x) + Message + -- R ----------------------------------- + * version: 4.4.0 + * path: '/usr/lib/R' + -- devtools ---------------------------- + * version: 2.4.6 + ! devtools or its dependencies out of + date: + "cli" + Update them with + `devtools::update_packages("devtools")` + -- dev package ------------------------- + * package: + * path: + +# print warns about outdated package deps + + Code + print(x) + Message + -- R ----------------------------------- + * version: 4.4.0 + * path: '/usr/lib/R' + -- devtools ---------------------------- + * version: 2.4.6 + -- dev package ------------------------- + * package: "mypkg" + * path: '/tmp/mypkg' + ! mypkg dependencies out of date: + "dplyr" and "tidyr" + Update them with + `devtools::install_dev_deps()` + +# print shows RStudio update message + + Code + print(x) + Message + -- R ----------------------------------- + * version: 4.4.0 + * path: '/usr/lib/R' + -- RStudio ----------------------------- + * version: "2024.04.0" + ! RStudio is out of date. + -- devtools ---------------------------- + * version: 2.4.6 + -- dev package ------------------------- + * package: + * path: + # check_for_rstudio_updates Code diff --git a/tests/testthat/test-sitrep.R b/tests/testthat/test-sitrep.R index 3a11128cd..89564048f 100644 --- a/tests/testthat/test-sitrep.R +++ b/tests/testthat/test-sitrep.R @@ -1,3 +1,60 @@ +test_that("print shows all checks passed", { + local_reproducible_output(width = 40) + x <- new_dev_sitrep( + r_version = R_system_version("4.4.0"), + r_path = "/usr/lib/R", + devtools_version = package_version("2.4.6") + ) + expect_snapshot(print(x)) +}) + +test_that("print warns when R is out of date", { + local_reproducible_output(width = 40) + x <- new_dev_sitrep( + r_version = R_system_version("4.3.0"), + r_path = "/usr/lib/R", + r_release_version = R_system_version("4.4.0"), + devtools_version = package_version("2.4.6") + ) + expect_snapshot(print(x)) +}) + +test_that("print warns about outdated devtools deps", { + local_reproducible_output(width = 40) + x <- new_dev_sitrep( + r_version = R_system_version("4.4.0"), + r_path = "/usr/lib/R", + devtools_version = package_version("2.4.6"), + devtools_deps = data.frame(package = c("rlang", "cli"), diff = c(0, -1)) + ) + expect_snapshot(print(x)) +}) + +test_that("print warns about outdated package deps", { + local_reproducible_output(width = 40) + x <- new_dev_sitrep( + r_version = R_system_version("4.4.0"), + r_path = "/usr/lib/R", + devtools_version = package_version("2.4.6"), + pkg = list(package = "mypkg", path = "/tmp/mypkg"), + pkg_deps = data.frame(package = c("dplyr", "tidyr"), diff = c(-1, -1)) + ) + expect_snapshot(print(x)) +}) + +test_that("print shows RStudio update message", { + local_reproducible_output(width = 40) + withr::local_envvar(POSITRON = "") + x <- new_dev_sitrep( + r_version = R_system_version("4.4.0"), + r_path = "/usr/lib/R", + devtools_version = package_version("2.4.6"), + rstudio_version = "2024.04.0", + rstudio_msg = "RStudio is out of date." + ) + expect_snapshot(print(x)) +}) + test_that("check_for_rstudio_updates", { skip_if_offline() skip_on_cran() From d170f1a78870139ea8b704f1acafe702c1680ca2 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 30 Jan 2026 17:24:40 -0600 Subject: [PATCH 2/5] Fix windows variation --- R/sitrep.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/sitrep.R b/R/sitrep.R index 1d5eed6c6..b4ad5c4a7 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -108,6 +108,7 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) { r_version = getRversion(), r_path = path_real(R.home()), r_release_version = r_release(), + is_windows = is_windows, has_build_tools = has_build_tools, rtools_path = if (has_build_tools) pkgbuild::rtools_path(), devtools_version = packageVersion("devtools"), @@ -125,6 +126,7 @@ new_dev_sitrep <- function( r_version = getRversion(), r_path = path_real(R.home()), r_release_version = r_version, + is_windows = FALSE, has_build_tools = TRUE, rtools_path = NULL, devtools_version = packageVersion("devtools"), @@ -139,6 +141,7 @@ new_dev_sitrep <- function( r_version = r_version, r_path = r_path, r_release_version = r_release_version, + is_windows = is_windows, has_build_tools = has_build_tools, rtools_path = rtools_path, devtools_version = devtools_version, @@ -165,7 +168,7 @@ print.dev_sitrep <- function(x, ...) { all_ok <- FALSE } - if (is_windows) { + if (x$is_windows) { cli::cli_rule("Rtools") if (x$has_build_tools) { kv_line("path", x$rtools_path, path = TRUE) From 4f69f4be9318e67d87a779e4f957241329c8d79d Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 30 Jan 2026 17:25:14 -0600 Subject: [PATCH 3/5] Increase width --- tests/testthat/_snaps/sitrep.md | 41 +++++++++++++++------------------ tests/testthat/test-sitrep.R | 10 ++++---- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/tests/testthat/_snaps/sitrep.md b/tests/testthat/_snaps/sitrep.md index 3df66ab91..548c26c8e 100644 --- a/tests/testthat/_snaps/sitrep.md +++ b/tests/testthat/_snaps/sitrep.md @@ -3,12 +3,12 @@ Code print(x) Message - -- R ----------------------------------- + -- R ------------------------------------------------------- * version: 4.4.0 * path: '/usr/lib/R' - -- devtools ---------------------------- + -- devtools ------------------------------------------------ * version: 2.4.6 - -- dev package ------------------------- + -- dev package --------------------------------------------- * package: * path: v All checks passed @@ -18,13 +18,13 @@ Code print(x) Message - -- R ----------------------------------- + -- R ------------------------------------------------------- * version: 4.3.0 * path: '/usr/lib/R' ! R is out of date (4.3.0 vs 4.4.0) - -- devtools ---------------------------- + -- devtools ------------------------------------------------ * version: 2.4.6 - -- dev package ------------------------- + -- dev package --------------------------------------------- * package: * path: @@ -33,17 +33,15 @@ Code print(x) Message - -- R ----------------------------------- + -- R ------------------------------------------------------- * version: 4.4.0 * path: '/usr/lib/R' - -- devtools ---------------------------- + -- devtools ------------------------------------------------ * version: 2.4.6 - ! devtools or its dependencies out of - date: + ! devtools or its dependencies out of date: "cli" - Update them with - `devtools::update_packages("devtools")` - -- dev package ------------------------- + Update them with `devtools::update_packages("devtools")` + -- dev package --------------------------------------------- * package: * path: @@ -52,33 +50,32 @@ Code print(x) Message - -- R ----------------------------------- + -- R ------------------------------------------------------- * version: 4.4.0 * path: '/usr/lib/R' - -- devtools ---------------------------- + -- devtools ------------------------------------------------ * version: 2.4.6 - -- dev package ------------------------- + -- dev package --------------------------------------------- * package: "mypkg" * path: '/tmp/mypkg' ! mypkg dependencies out of date: "dplyr" and "tidyr" - Update them with - `devtools::install_dev_deps()` + Update them with `devtools::install_dev_deps()` # print shows RStudio update message Code print(x) Message - -- R ----------------------------------- + -- R ------------------------------------------------------- * version: 4.4.0 * path: '/usr/lib/R' - -- RStudio ----------------------------- + -- RStudio ------------------------------------------------- * version: "2024.04.0" ! RStudio is out of date. - -- devtools ---------------------------- + -- devtools ------------------------------------------------ * version: 2.4.6 - -- dev package ------------------------- + -- dev package --------------------------------------------- * package: * path: diff --git a/tests/testthat/test-sitrep.R b/tests/testthat/test-sitrep.R index 89564048f..c2debee42 100644 --- a/tests/testthat/test-sitrep.R +++ b/tests/testthat/test-sitrep.R @@ -1,5 +1,5 @@ test_that("print shows all checks passed", { - local_reproducible_output(width = 40) + local_reproducible_output(width = 60) x <- new_dev_sitrep( r_version = R_system_version("4.4.0"), r_path = "/usr/lib/R", @@ -9,7 +9,7 @@ test_that("print shows all checks passed", { }) test_that("print warns when R is out of date", { - local_reproducible_output(width = 40) + local_reproducible_output(width = 60) x <- new_dev_sitrep( r_version = R_system_version("4.3.0"), r_path = "/usr/lib/R", @@ -20,7 +20,7 @@ test_that("print warns when R is out of date", { }) test_that("print warns about outdated devtools deps", { - local_reproducible_output(width = 40) + local_reproducible_output(width = 60) x <- new_dev_sitrep( r_version = R_system_version("4.4.0"), r_path = "/usr/lib/R", @@ -31,7 +31,7 @@ test_that("print warns about outdated devtools deps", { }) test_that("print warns about outdated package deps", { - local_reproducible_output(width = 40) + local_reproducible_output(width = 60) x <- new_dev_sitrep( r_version = R_system_version("4.4.0"), r_path = "/usr/lib/R", @@ -43,7 +43,7 @@ test_that("print warns about outdated package deps", { }) test_that("print shows RStudio update message", { - local_reproducible_output(width = 40) + local_reproducible_output(width = 60) withr::local_envvar(POSITRON = "") x <- new_dev_sitrep( r_version = R_system_version("4.4.0"), From b067700d24edb1597adbb81a2b14f174573a8cb8 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 10 Feb 2026 16:19:26 -0800 Subject: [PATCH 4/5] Tweaks --- R/sitrep.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/sitrep.R b/R/sitrep.R index b4ad5c4a7..9c57e2701 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -174,7 +174,7 @@ print.dev_sitrep <- function(x, ...) { kv_line("path", x$rtools_path, path = TRUE) } else { cli::cli_bullets(c( - "!" = "{.field RTools} is not installed.", + "!" = "{.field Rtools} is not installed.", " " = "Download and install it from: {.url https://cloud.r-project.org/bin/windows/Rtools/}" )) } @@ -197,7 +197,7 @@ print.dev_sitrep <- function(x, ...) { devtools_deps_old <- x$devtools_deps$diff < 0 if (any(devtools_deps_old)) { cli::cli_bullets(c( - "!" = "{.field devtools} or its dependencies out of date:", + "!" = "{.pkg devtools} or its dependencies out of date:", " " = "{.val {x$devtools_deps$package[devtools_deps_old]}}", " " = "Update them with {.code devtools::update_packages(\"devtools\")}" )) From 95ff4b355f7863f77c181ee29cf3978e4052e320 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 10 Feb 2026 16:36:13 -0800 Subject: [PATCH 5/5] Namespace these --- R/sitrep.R | 4 ++-- inst/WORDLIST | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/sitrep.R b/R/sitrep.R index 9c57e2701..c37adbaff 100644 --- a/R/sitrep.R +++ b/R/sitrep.R @@ -111,7 +111,7 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) { is_windows = is_windows, has_build_tools = has_build_tools, rtools_path = if (has_build_tools) pkgbuild::rtools_path(), - devtools_version = packageVersion("devtools"), + devtools_version = utils::packageVersion("devtools"), devtools_deps = remotes::package_deps("devtools", dependencies = NA), pkg_deps = if (!is.null(pkg)) { remotes::dev_package_deps(pkg$path, dependencies = TRUE) @@ -129,7 +129,7 @@ new_dev_sitrep <- function( is_windows = FALSE, has_build_tools = TRUE, rtools_path = NULL, - devtools_version = packageVersion("devtools"), + devtools_version = utils::packageVersion("devtools"), devtools_deps = data.frame(package = character(), diff = numeric()), pkg_deps = NULL, rstudio_version = NULL, diff --git a/inst/WORDLIST b/inst/WORDLIST index 91a0c756e..f36162419 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -53,6 +53,7 @@ SHA Studer Takahashi Titov +UI UNC VignetteBuilder WARNINGs