8

Can I include some PDF in the pkg/doc folder so that the vignette function works, but no corresponding Rnw, Rtex, etc exists?

I am thinking of slides or documents containing markdown text weaved with R chunks, which have a different build process and hence different file extensions.

The writing R extensions guide suggests that it should be possible to include documents which can not be build at installation time, but the vignette function seems to look for files with special extensions (Rnw, Rtex, etc) and also for a file called vignette.rds.

Any hints are appreciated.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103

3 Answers3

5

This is supported natively as of R 3.0.0, see http://yihui.name/knitr/demo/vignette/.

Instructions to use knitr as vignette engine boil down to:

  1. add %\VignetteEngine{knitr::knitr} to the Rnw source document (note you still need %\VignetteIndexEntry{} as before)
  2. specify VignetteBuilder: knitr in the package DESCRIPTION file
  3. add Suggests: knitr in DESCRIPTION if knitr is needed only for vignettes

See also the official R documentation on that topic.

krlmlr
  • 25,056
  • 14
  • 120
  • 217
5

I asked about this several years ago, and while Fritz Leisch is amenable to the idea, he hasn't had the time to implement it.

hadley
  • 102,019
  • 32
  • 183
  • 245
5

(Cross-posted from a response I just left on R-help:)

As a workaround, you could include your own xvignette function in your package: see below. It won't show you indices, but it will pick up any appropriately named file that you include in the inst/doc directory of your package ...

xvignette <- function(vname,pkg,ext="pdf") {
   vname <- paste(vname,ext,sep=".")
   fn <- system.file("doc",vname,package=pkg)
   if (nchar(fn)==0) stop("file not found")
   utils:::print.vignette(list(pdf=fn))
   invisible(fn)
 }

You'll have to somehow alert your package users to the fact that this alternative documentation exists -- perhaps in the help file for the package itself.

You might fill in the default value of pkg above with your package name to make it easier on the user: I thought about using some variant of getPackageName(environment(xvignette)) to do it automatically, but that seems too complicated ...

Brian Ripley also mentioned in his response to the question that:

At present vignette() means Sweave documents, as only they have metadata like titles. This is planned to be changed soon.

... but I don't know what "soon" means (it will be about 6 months until 2.14.0 comes out, I think)

edit: http://article.gmane.org/gmane.comp.lang.r.devel/28449 details another workaround (creating a dummy vignette that incorporates the existing PDF file)

edit 2: And

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453