如何产生多种格式的R包小插图? [英] How do I produce R package vignettes in multiple formats?

查看:54
本文介绍了如何产生多种格式的R包小插图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 knitr rmarkdown 编写R包的小插图.借助 pandoc 的魔力,可以轻松地将这些文档转换为多种格式.我想通过同时提供HTML和PDF小插图来利用这一点. rmarkdown 支持在文档元数据块中为多种输出格式指定参数.例如,我可能有这样的东西:

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:

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

在R命令行中,我可以使用rmarkdown::render轻松地构建一个或两个输出文档.但是,在构建软件包时,仅使用最先列出的输出格式.我试图包含一个 Makefile ,该文件通过包含一些类似的内容来构建

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

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

可以成功生成所有输出文件,但R只能识别其中一个为小插图.要使docs/中包含其他输出,必须将它们添加到 .install_extras .虽然可以确保通过HTML索引对其进行访问,但它们与小插图分开列出,而且我认为不能从R内(通过vignette())对其进行访问.

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()).

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

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

推荐答案

两件事:

  1. 您可以包含"公共内容,并具有两个带有不同标题的源文件,或者,

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

如果多余的小插图确实没有出现在索引中,请编写自己的小插图.来自Writing R扩展:在安装时,将根据\ VignetteIndexEntry语句自动创建包中所有小插图的HTML索引,除非在目录inst/doc中存在文件index.html.此索引从HTML帮助索引链接到包裹."小插图索引条目也可能是将您可能同名的小插图识别为不同的线索.

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包小插图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆