Skip to content

Commit

Permalink
do not throw an error in R CMD check when checking a package on CRAN …
Browse files Browse the repository at this point in the history
…but rmarkdown/markdown/Pandoc is not available (#1864)

this is like a trolley problem to me---I still can't accept the consequence that I'm going to kill 200 packages on CRAN if I throw an error when the package author didn't declare dependence on rmarkdown or markdown
  • Loading branch information
yihui committed Sep 8, 2021
1 parent 6ea3cca commit 9a80a00
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.33.9
Version: 1.33.10
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
3 changes: 3 additions & 0 deletions R/utils-conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ knit2html = function(
input, output = NULL, ..., envir = parent.frame(), text = NULL,
quiet = FALSE, encoding = 'UTF-8', force_v1 = getOption('knitr.knit2html.force_v1', FALSE)
) {
if (is_cran_check() && !has_package('markdown'))
return(vweave_empty(input, .reason = 'markdown'))

if (!force_v1 && is.null(text)) {
if (length(grep('^---\\s*$', head(read_utf8(input), 1)))) warning2(
'It seems you should call rmarkdown::render() instead of knitr::knit2html() ',
Expand Down
6 changes: 4 additions & 2 deletions R/utils-vignettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ vtangle_empty = function(file, ...) {
}

# when neither Pandoc nor markdown is available, just silently skip the vignette
vweave_empty = function(file, ...) {
vweave_empty = function(file, ..., .reason = 'Pandoc') {
out = with_ext(file, 'html')
writeLines('The vignette could not be built because Pandoc is not available.', out)
writeLines(sprintf('The vignette could not be built because %s is not available.', .reason), out)
out
}

Expand All @@ -97,6 +97,8 @@ register_vignette_engines = function(pkg) {
vig_engine('docco_linear', vweave_docco_linear, '[.][Rr](md|markdown)$')
vig_engine('docco_classic', vweave_docco_classic, '[.][Rr]mk?d$')
vig_engine('rmarkdown', function(...) {
if (is_cran_check() && !has_package('rmarkdown'))
return(vweave_empty(..., .reason = 'rmarkdown'))
if (pandoc_available()) {
vweave_rmarkdown(...)
} else {
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ is_lyx = function() {
grepl('[.]Rnw$', args[1]) && !is.na(Sys.getenv('LyXDir', NA))
}

# detect if running on CRAN (assuming that CRAN does not set CI or NOT_CRAN=true)
is_cran = function() {
!any(tolower(Sys.getenv(c('CI', 'NOT_CRAN'))) == 'true')
}

is_cran_check = function() {
is_cran() && is_R_CMD_check()
}

# round a number to getOption('digits') decimal places by default, and format()
# it using significant digits if the option knitr.digits.signif = TRUE
round_digits = function(x) {
Expand Down

0 comments on commit 9a80a00

Please sign in to comment.