From 7a5b7cdacc3093d7444bf7b2e137564978e082f9 Mon Sep 17 00:00:00 2001 From: Tan Ho Date: Fri, 19 Sep 2025 12:13:11 -0400 Subject: [PATCH 1/2] add _R_CHECK envvar printing to rcmdcheck(), closes #172 --- NEWS.md | 2 ++ R/package.R | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 121f54e..340cf53 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ * `cran_check_results()` works again. +* `rcmdcheck()` now will print rcheck envvars ([#172](https://github.com/r-lib/rcmdcheck/issues/172)) + # rcmdcheck 1.4.0 * `cran_check_results()` now downloads results in parallel, so it is diff --git a/R/package.R b/R/package.R index 6a6c43e..b9beda7 100644 --- a/R/package.R +++ b/R/package.R @@ -227,9 +227,41 @@ do_check <- function( } # user supplied env vars take precedence - if (length(env)) chkenv[names(env)] <- env + if (length(env)) { + chkenv[names(env)] <- env + } + + if (!quiet) { + cat_head("R CMD check") + cat_line() + all_vars <- Sys.getenv() + rchk_vars <- all_vars[ + grep("_R_CHECK|NOT_CRAN|RCMDCHECK|R_TESTS", names(all_vars)) + ] + rchk_vars[names(env)] <- env + if (length(rchk_vars) == 0) { + cli::cat_bullet( + "No R CMD check env vars set", + col = "darkgrey", + bullet = "line", + bullet_col = "darkgrey" + ) + } + if (length(rchk_vars) > 0) { + cli::cat_bullet( + "R CMD check env vars set:", + col = "darkgrey", + bullet = "line", + bullet_col = "darkgrey" + ) + cli::cat_bullet( + paste0(format(names(rchk_vars)), " = ", unname(rchk_vars)), + col = "darkgrey" + ) + cat_line() + } + } - if (!quiet) cat_head("R CMD check") callback <- if (!quiet) detect_callback(as_cran = "--as-cran" %in% args) res <- rcmd_safe( "check", From c889c41df7d0602f62ed620703f6f4b15a12b88d Mon Sep 17 00:00:00 2001 From: Tan Date: Fri, 26 Sep 2025 11:36:33 -0400 Subject: [PATCH 2/2] suggestions from @hadley review --- NEWS.md | 2 +- R/package.R | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/NEWS.md b/NEWS.md index 340cf53..ec37cbe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,7 +10,7 @@ * `cran_check_results()` works again. -* `rcmdcheck()` now will print rcheck envvars ([#172](https://github.com/r-lib/rcmdcheck/issues/172)) +* `rcmdcheck()` now will print relevant environment variables (#172, @tanho63) # rcmdcheck 1.4.0 diff --git a/R/package.R b/R/package.R index b9beda7..2e172e2 100644 --- a/R/package.R +++ b/R/package.R @@ -143,7 +143,9 @@ rcmdcheck <- function( } # Add pandoc to the PATH, for R CMD build and R CMD check - if (should_use_rs_pandoc()) local_path(Sys.getenv("RSTUDIO_PANDOC")) + if (should_use_rs_pandoc()) { + local_path(Sys.getenv("RSTUDIO_PANDOC")) + } pkgbuild::without_cache(pkgbuild::local_build_tools()) @@ -175,7 +177,9 @@ rcmdcheck <- function( on.exit(unlink(out$session_info, recursive = TRUE), add = TRUE) - if (isTRUE(out$timeout)) message("R CMD check timed out") + if (isTRUE(out$timeout)) { + message("R CMD check timed out") + } res <- new_rcmdcheck( stdout = out$result$stdout, @@ -188,7 +192,9 @@ rcmdcheck <- function( ) # Automatically delete temporary files when this object disappears - if (cleanup) res$cleaner <- auto_clean(check_dir) + if (cleanup) { + res$cleaner <- auto_clean(check_dir) + } handle_error_on(res, error_on) @@ -239,17 +245,10 @@ do_check <- function( grep("_R_CHECK|NOT_CRAN|RCMDCHECK|R_TESTS", names(all_vars)) ] rchk_vars[names(env)] <- env - if (length(rchk_vars) == 0) { - cli::cat_bullet( - "No R CMD check env vars set", - col = "darkgrey", - bullet = "line", - bullet_col = "darkgrey" - ) - } + if (length(rchk_vars) > 0) { cli::cat_bullet( - "R CMD check env vars set:", + "With:", col = "darkgrey", bullet = "line", bullet_col = "darkgrey" @@ -278,7 +277,9 @@ do_check <- function( ) # To print an incomplete line on timeout or crash - if (!is.null(callback) && (res$timeout || res$status != 0)) callback("\n") + if (!is.null(callback) && (res$timeout || res$status != 0)) { + callback("\n") + } # Non-zero status is an error, the check process failed # R CMD check returns 1 for installation errors, we don't want to error