Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have R vignette with a pre-compiled PDF with manual index.html show up the vignette list?

Tags:

r

r-mosaic

I want to include a pre-compiled PDF as a vignette in a R package. The PDF is not generated via Sweave. Without a .Rnw to process, there is no \VignetteIndexEntry to cause the usual automatic generation of index.html and Meta/vignette.rds.

I created an index.html in inst/doc that is copied into doc during installation. This is corrected linked from the main package help page. However, when I load the package and execute browseVignettes("MyPackage"), I get

No vignettes found by browseVignettes("MyPackage")

This makes sense, because R apparently has no way to know that the package has a vignette. The installed package has no Meta/vignette.rds file. Can I somehow get my PDF to appear with browseVignettes()?

pdfpages

I'm familiar with the approach taken by the mosaic package, which is to use pdfpages to include the entire PDF. While clever, I feel like there should be a better way that avoids the proliferation of files.

like image 420
kmm Avatar asked Oct 29 '12 20:10

kmm


3 Answers

Right after Yihui....

Make a fake Rnw that looks like this:

%\VignetteIndexEntry{User manual}
\documentclass{article}
\begin{document}
\end{document}

And put it in inst/doc along side your precompiled vignette and you will be all set.

like image 195
Bryan Hanson Avatar answered Nov 15 '22 22:11

Bryan Hanson


R definitely needs a better way to deal with vignettes: http://comments.gmane.org/gmane.comp.lang.r.devel/31967 Before my proposal is approved and implemented, we still have to live with the dark voodoo of Makefile. For example, you can put a fake.Rnw and a real.pdf under inst/doc, and mv real.pdf fake.pdf in the Makefile. In fake.Rnw, you just follow the rule of \VignetteIndexEntry{}.

like image 24
Yihui Xie Avatar answered Nov 15 '22 20:11

Yihui Xie


The mosaic package now apparently uses the R.rsp package which has an "asis" driver that allows including an existing file and creating the VignetteIndexEntry. This looks much less like a hack than using pdfpages or a dummy .Rnw file (which doesn't seem to work anymore in R 3.1).

Example: For a file V1MinimalR.pdf, there is a corresponding V1MinimalR.pdf.asis file with the following contents:

%\VignetteIndexEntry{Minimal R for Intro Stats}
%\VignetteEngine{R.rsp::asis}

The DESCRIPTION contains (among others) the following:

Suggests: R.rsp
VignetteBuilder: knitr, R.rsp

This is also detailed in this answer by Henrik Bengtsson, the author of the R.rsp package.

like image 21
krlmlr Avatar answered Nov 15 '22 22:11

krlmlr