diff --git a/DESCRIPTION b/DESCRIPTION index a4f45033d8..2f310313b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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"), diff --git a/R/utils-conversion.R b/R/utils-conversion.R index 8fd48e8470..82b71ae15e 100644 --- a/R/utils-conversion.R +++ b/R/utils-conversion.R @@ -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() ', diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index 2969e635ad..23f06d7461 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -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 } @@ -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 { diff --git a/R/utils.R b/R/utils.R index 6430a4bc2e..012a00786f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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) {