Skip to content

Commit d5190a8

Browse files
Merge pull request #1267 from MichaelChirico/patch-4
Give a friendlier failure when lacking knitr
2 parents fe6ae64 + 377d573 commit d5190a8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

R/transform-code.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ transform_code <- function(path, fun, ..., dry) {
3636
#' @inheritParams separate_chunks
3737
#' @keywords internal
3838
transform_mixed <- function(lines, transformer_fun, filetype) {
39+
if (filetype %in% c("Rnw", "Rmd") && !rlang::is_installed("knitr")) {
40+
rlang::abort("{knitr} is required to process vignette files (Rmd, Rnw)")
41+
}
3942
chunks <- separate_chunks(lines, filetype)
4043
chunks$r_chunks <- map(chunks$r_chunks, transform_mixed_non_empty,
4144
transformer_fun = transformer_fun
@@ -168,9 +171,8 @@ get_engine_pattern <- function() {
168171
#' @inheritParams separate_chunks
169172
#' @keywords internal
170173
get_knitr_pattern <- function(filetype) {
171-
if (filetype == "Rnw") {
172-
knitr::all_patterns[["rnw"]]
173-
} else if (filetype == "Rmd") {
174-
knitr::all_patterns[["md"]]
175-
}
174+
switch(filetype,
175+
Rnw = knitr::all_patterns[["rnw"]],
176+
Rmd = knitr::all_patterns[["md"]]
177+
)
176178
}

0 commit comments

Comments
 (0)