Skip to content

Commit

Permalink
the first step for #1864: warn if markdown is not a dependency of the…
Browse files Browse the repository at this point in the history
… package containing vignettes based on the knitr::knitr engine
  • Loading branch information
yihui committed Jun 21, 2020
1 parent 36079c6 commit 54577dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions R/utils-conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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', ...)
Expand Down

0 comments on commit 54577dd

Please sign in to comment.