RMarkdown error: Error in if (grepl("(html|gitbook|bs4)", format)) return("html")

I have a small R package that I use to distribute data sets for a class that I teach. I recently started updating materials for the upcoming semester but when I try to knit .rmd files using the knit button in RStudio, I get the following error:

Error in if (grepl("(html|gitbook|bs4)", format)) return("html") : 
  argument is of length zero
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> render_book -> target_format
Execution halted

This occurs for any .rmd file (vignettes that have worked fine in the past, xaringan slides, default .rmd template). Using rmarkdown::render() seems to work fine, so I can simply use that, though would prefer the knit button to work if possible. Google has not provided any hints so any tips on figuring out what is causing the error would be appreciated. R session info below.

R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 compiler_4.2.0 pillar_1.8.0 class_7.3-20
[5] tools_4.2.0 digest_0.6.29 evaluate_0.15 lifecycle_1.0.1
[9] tibble_3.1.8 pkgconfig_2.0.3 rlang_1.0.4 DBI_1.1.3
[13] cli_3.3.0 rstudioapi_0.13 yaml_2.3.5 xfun_0.31
[17] fastmap_1.1.0 e1071_1.7-11 dplyr_1.0.9 knitr_1.39
[21] generics_0.1.3 vctrs_0.4.1 classInt_0.4-7 grid_4.2.0
[25] tidyselect_1.1.2 glue_1.6.2 sf_1.0-7 R6_2.5.1
[29] fansi_1.0.3 bookdown_0.27 xaringan_0.25 rmarkdown_2.14
[33] purrr_0.3.4 tidyr_1.2.0 magrittr_2.0.3 backports_1.4.1
[37] htmltools_0.5.2 units_0.8-0 assertthat_0.2.1 KernSmooth_2.23-20
[41] utf8_1.2.2 proxy_0.4-27 broom_0.8.0

Hi,

This error is thrown from a function in bookdown. Are you using a Bookdown project here ? It does not seem so from your explanation.

It seems this happens because RStudio IDE thinks that you are in a Bookdown project, and tries to use render_site() function on the document, and then using the Bookdown function. Do you have an index.Rmd in the project with site: bookdown::bookdown_site() ? This is usually the way a bookdown project is set up for RStudio IDE to know about it.

I am assuming your are working in a RStudio project alos. Is that the case ?

Overall, can you share more on your project structure folder to understand this better ?

Thanks @cderv - that was the issue. Deleting the index.rmd file eliminated the error message and everything knits properly now.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.