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

Duncan Murdoch murdoch at stats.uwo.ca
Thu Nov 9 13:16:19 CET 2006

On 11/9/2006 6:37 AM, Agner Fog wrote:
> 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.

Actually how you built the .pdf is irrelevant, but it does look for file 
with the same name and one of these extensions:

  "Rnw"  "rnw"  "Snw"  "snw"  "Rtex" "rtex" "Stex" "stex"

So you could just create a zero length file with the same basename and 
one of those extensions, and it should work.

I don't know if this restriction is intentional.

Duncan Murdoch

> 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.
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list