Question about usethis vignette-template

This question is more for my curiosity than anything - everything seems to work OK.

When you create a vignette using usethis::use_vignette(), you get a template that includes something like this:

---
title: "title"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{title}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

If you look at %\VignetteEngine{}, you see a reference to knitr::rmarkdown.

As far as I can tell:

knitr::rmarkdown
#> Error: 'rmarkdown' is not an exported object from 'namespace:knitr'

Created on 2019-05-30 by the reprex package (v0.2.1)

What's going on here? :face_with_monocle:

1 Like

This is just the way you refer to a vignette engine - it is disturbing as this is the same syntax as en exported object, but it is to be used in tools::vignetteEngine.

Try tools::vignetteEngine("knitr::rmarkdown") to get the rmardown engine registered by knitr. You'll find the engine in the code : https://github.com/yihui/knitr/blob/master/R/utils-vignettes.R

There is several engine - you can refer to help("vignette_engines", package = "knitr")

You can look into CRAN document to see also how vignettes work.

Hope it helps!

4 Likes

Thanks Christophe!

I'm glad there is a rational explanation - I agree that the notation can cause confusion. Until today, I had not even noticed this - then I couldn't "unsee" it...

Thanks again!

1 Like

I believe this is how the R vignette mechanism works and you can't change the syntax :relaxed:

The rmarkdown engine from knitr is required for Rmd vignette to use rmarkdown::render() and you should use it your vignette. That is why it is in the template. :slight_smile:

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