[R] [Rd] How to link to vignette from .Rd file

Agner Fog agner at agner.org
Thu Nov 9 12:37:59 CET 2006


Thanks for the tip. Actually I found that I can just write 
vignette("vignettename") in a demo. I think that's the easiest way to 
link to a .pdf file.

It works only if the .pdf file is built from a Sweave file. I thought 
that I could just put a .pdf file and an index.html in inst/doc/ but I 
get no link to the index.html from anywhere. Using a Sweave file seems 
to be the only solution that works.


Prof Brian Ripley wrote:

> This looks very like the print method for vignettes. This is
>
>> utils:::print.vignette
>
> function (x, ...)
> {
>     if (length(x$pdf)) {
>         if (.Platform$OS.type == "windows")
>             shell.exec(x$pdf)
>         else system(paste(getOption("pdfviewer"), x$pdf, "&"))
>     }
>     else {
>         warning(gettextf("vignette '%s' has no PDF", x$topic),
>             call. = FALSE, domain = NA)
>     }
> }
>
> which is more elegant in several ways than those solutions earlier in 
> this thread (the one below does not even work on Win9x or if CMD.exe 
> is not in the path).
>
>>> Duncan Murdoch wrote:
>>>
>>>>
>>>> The demo system can be used to compensate for limitations of the help
>>>> system.
>>>> You can display PDF files from any package subdirectory using a 
>>>> demo file
>>>> like this (named demo/ReadPkgDoc.R, and documented in demo/00Index):
>>>>
>>>> # ReadPkgDoc.R -- Displays a PDF file as a demo
>>>> #
>>>> isWindows <- (Sys.info()['sysname'] == 'Windows')
>>>> file <- system.file("doc", "PkgManual.pdf", package="PkgName")
>>>> if(isWindows) { # Windows automatically finds executable based on file
>>>> type.
>>>>  system(paste("CMD /C ", file, "\n"))
>>>> } else { # Change this to use path to Adobe reader if desired.
>>>>  system(paste("xpdf ", file, "\n"))
>>>> }
>>>>
>>>> To create the PDF file from the Rd file use R CMD Rd2dvi, and dvipdf.
>>>
>



More information about the R-help mailing list