Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R -- Vignettes that are not made by Sweave possible?

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.

like image 302
Karsten W. Avatar asked Jul 09 '11 12:07

Karsten W.


2 Answers

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.

like image 131
hadley Avatar answered Nov 19 '22 22:11

hadley


(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

  • here's what Yihui Xie has to say about including knitr-based vignettes in packages (essentially another "dummy vignette" strategy)
  • vignette about non-Sweave vignettes from the R.rsp package
like image 5
Ben Bolker Avatar answered Nov 19 '22 23:11

Ben Bolker