diff --git a/NEWS.md b/NEWS.md index 1d1bbe1c05..458e1625a8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -26,6 +26,8 @@ - For a non-matrix object passed to `kable()`, its columns are formatted individually via `format()`. Previously, the whole object is coerced via `as.matrix()` (thanks, @thebioengineer, #1827). +- For packages that contain R Markdown vignettes using the vignette engines based on the **markdown** package (e.g., `knitr::knitr`), the **markdown** package should be declared in `Suggests` in the package `DESCRIPTION` unless it has already been declared as a dependency in other fields. For this version of **knitr**, you will see a warning in `R CMD check` in the CRAN incoming check. In the future, you may see a warning in a regular `R CMD check`, so please add **markdown** to `Suggests` at your earliest convenience. If it is not clear how to do it, please see #1864. + ## MINOR CHANGES - `knitr::image_uri()` calls `xfun::base64_uri()` instead of `markdown:::.b64EncodeFile()` now. diff --git a/R/utils-conversion.R b/R/utils-conversion.R index e86a544b91..852f601d01 100644 --- a/R/utils-conversion.R +++ b/R/utils-conversion.R @@ -109,6 +109,21 @@ knit2pdf = function( #' unlink(c('test.Rmd', 'test.html', 'test.md')) knit2html = function(input, output = NULL, ..., envir = parent.frame(), text = NULL, quiet = FALSE, encoding = 'UTF-8', force_v1 = FALSE) { + # packages containing vignettes using R Markdown v1 should declare dependency + # on 'markdown' in DESCRIPTION (typically in Suggests) + if (!is.na(pkg <- Sys.getenv('_R_CHECK_PACKAGE_NAME_', NA)) && pkg != 'markdown') { + info = packageDescription(pkg, fields = c('Depends', 'Imports', 'Suggests')) + if (!'markdown' %in% unlist(strsplit(unlist(info), '[[:space:],]+'))) { + if (is_CRAN_incoming()) stop2( + "The 'markdown' package should be declared as a dependency of the '", pkg, + "' package (e.g., in the 'Suggests' field of DESCRIPTION), because it ", + "contains vignette(s) built with the 'markdown' package. Please see ", + "https://github.com/yihui/knitr/issues/1864 for more information." + ) + } + } + # TODO: remove the above hack in the future when no CRAN packages have the issue + if (!force_v1 && is.null(text)) { signal = if (is_R_CMD_check()) warning2 else stop2 if (length(grep('^---\\s*$', head(read_utf8(input), 1)))) signal( diff --git a/R/utils.R b/R/utils.R index 5ab4d703d7..3035e5d6e5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -772,6 +772,10 @@ is_R_CMD_check = function() { any(c('_R_CHECK_TIMINGS_', '_R_CHECK_LICENSE_') %in% names(Sys.getenv())) } +is_CRAN_incoming = function() { + isTRUE(as.logical(Sys.getenv('_R_CHECK_CRAN_INCOMING_REMOTE_'))) +} + # is the inst dir under . or ..? differs in R CMD build/INSTALL and devtools/roxygen2 inst_dir = function(...) { p = file.path(c('..', '.'), 'inst', ...)