Skip to content

Commit 854edfe

Browse files
check installation in transform_mixed instead
1 parent 2f971a8 commit 854edfe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

R/transform-code.R

Lines changed: 7 additions & 7 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,11 +171,8 @@ get_engine_pattern <- function() {
168171
#' @inheritParams separate_chunks
169172
#' @keywords internal
170173
get_knitr_pattern <- function(filetype) {
171-
if (!filetype %in% c("Rnw", "Rmd")) {
172-
return(NULL)
173-
}
174-
if (!rlang::is_installed("knitr")) {
175-
rlang::abort("{knitr} is required to process vignette files (Rmd, Rnw)")
176-
}
177-
knitr::all_patterns[[if (filetype == "Rnw") "rnw" else "md"]]
174+
switch(filetype,
175+
Rnw = knitr::all_patterns[["rnw"]],
176+
Rmd = knitr::all_patterns[["md"]]
177+
)
178178
}

0 commit comments

Comments
 (0)