如何以多种格式生成R包装晕影?

时间:2023-01-18 07:48:36

I use knitr and rmarkdown to write vignettes for R packages. Thanks to the magic of pandoc it is easy to turn these documents into a variety of formats. I would like to take advantage of this by offering vignettes as both HTML and PDF. There is support from rmarkdown to specify parameters for multiple output formats in the documents metadata block. For example, I might have something like this:

我使用knitr和rmarkdown为R包编写晕影。由于pandoc的神奇之处,很容易将这些文档转换为各种格式。我想通过提供HTML和PDF的插图来利用这一点。 rmarkdown支持在文档元数据块中指定多种输出格式的参数。例如,我可能会有这样的事情:

output:
  html_document:
    standalone: true
    smart: true
    normalize: true
    toc: true
    highlight: tango
    self-contained: true
    theme: cerulean
  pdf_document:
    toc: true
    highlight: tango
geometry: margin=2cm
documentclass: article
classoption: a4paper

From the R command-line I can use rmarkdown::render to build either one or both of the output documents without difficulties. However, when the package is build only the output format that is listed first is used. I have tried to include a Makefile that builds both by including something along the lines of

从R命令行我可以使用rmarkdown :: render来构建一个或两个输出文档而不会有任何困难。但是,在构建包时,仅使用首先列出的输出格式。我试图包含一个Makefile,它通过包含一些东西来构建

all: %.Rmd
    $(R_HOME)/bin/Rscript -e "rmarkdown::render('$*.Rmd', 'all')"

and that is successful in the sense that all output files are generated but only one of them is recognised as vignette by R. To get additional outputs included in docs/ they have to be added to .install_extras. While that ensures they are accessible via the HTML index they are listed separately from the vignettes and and I don't think they can be accessed from within R (via vignette()).

并且这是成功的,因为生成了所有输出文件但是其中只有一个被R识别为晕影。要获得docs /中包含的其他输出,必须将它们添加到.install_extras。虽然这确保它们可以通过HTML索引访问,但它们与小插图分开列出,我认为不能从R中访问它们(通过vignette())。

Is there a better way (or any automated way) to do this?

有没有更好的方法(或任何自动化的方式)来做到这一点?

1 个解决方案

#1


1  

Two things:

两件事情:

  1. you could 'include' the common content and have two source files with different headers, or,

    你可以'包含'公共内容,并有两个不同标题的源文件,或者,

  2. if the extra vignette really doesn't show up in the index, write your own. From Writing R extensions: "At install time an HTML index for all vignettes in the package is automatically created from the \VignetteIndexEntry statements unless a file index.html exists in directory inst/doc. This index is linked from the HTML help index for the package." The vignette index entry might also be a clue to having your probably identically named vignettes be recognized as distinct.

    如果额外的小插图真的没有出现在索引中,请自己编写。来自编写R扩展:“在安装时,除了目录inst / doc中存在文件index.html之外,将自动从\ VignetteIndexEntry语句创建包中所有晕影的HTML索引。此索引从HTML帮助索引链接到包。”晕影索引条目也可能是将您可能具有相同名称的晕影识别为不同的线索。

#1


1  

Two things:

两件事情:

  1. you could 'include' the common content and have two source files with different headers, or,

    你可以'包含'公共内容,并有两个不同标题的源文件,或者,

  2. if the extra vignette really doesn't show up in the index, write your own. From Writing R extensions: "At install time an HTML index for all vignettes in the package is automatically created from the \VignetteIndexEntry statements unless a file index.html exists in directory inst/doc. This index is linked from the HTML help index for the package." The vignette index entry might also be a clue to having your probably identically named vignettes be recognized as distinct.

    如果额外的小插图真的没有出现在索引中,请自己编写。来自编写R扩展:“在安装时,除了目录inst / doc中存在文件index.html之外,将自动从\ VignetteIndexEntry语句创建包中所有晕影的HTML索引。此索引从HTML帮助索引链接到包。”晕影索引条目也可能是将您可能具有相同名称的晕影识别为不同的线索。