R——可能不是由 Sweave 制作的晕影吗?

发布于 2024-11-19 08:41:27 字数 304 浏览 3 评论 0原文

我可以在 pkg/doc 文件夹中包含一些 PDF 以便 vignette 功能正常工作,但不存在相应的 Rnw、Rtex 等吗?

我正在考虑包含用 R 块编织的 markdown 文本的幻灯片或文档,它们具有不同的构建过程,因此具有不同的文件扩展名。

编写 R 扩展指南建议应该可以包含在安装时无法构建的文档,但是 vignette 函数似乎会查找具有特殊扩展名(Rnw、Rtex 等)的文件,并且也适用于名为 vignette.rds 的文件。

任何提示表示赞赏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妄断弥空 2024-11-26 08:41:27

几年前我问过这个问题,虽然弗里茨·莱施(Fritz Leisch)同意这个想法,但他没有时间实施它。

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.

简单气质女生网名 2024-11-26 08:41:27

(交叉发布于我刚刚在 R-help 上留下的回复:)

作为解决方法,您可以在包中包含您自己的 xvignette 函数:请参见下文。
它不会向您显示索引,但会选取您的 inst/doc 目录中包含的任何适当命名的文件。
包...

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)
 }

您必须以某种方式提醒您的包用户这个替代文档存在的事实 - 也许在包本身的帮助文件中。

您可以用您的包名称填写上面的 pkg 的默认值,以方便用户:我考虑过使用 getPackageName(environment(xvignette)) 的某些变体自动完成,但这似乎太复杂了......

Brian Ripley 在回答问题时还提到:

目前 vignette() 表示 Sweave 文档,因为只有它们有
元数据,如标题。计划很快对此进行更改。

...但我不知道“很快”是什么意思(我认为 2.14.0 发布大约需要 6 个月)

编辑http://article.gmane.org/gmane.comp.lang.r.devel/28449 详细介绍了另一个解决方法(创建一个包含现有 PDF 文件的虚拟小插图)

编辑 2:以下

(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

想你的星星会说话 2024-11-26 08:41:27

从 R 3.0.0 开始,本机支持此功能,请参阅 http://yihui.name/knitr/demo/小插图/

使用 knitr 作为晕影引擎的说明归结为:

  1. %\VignetteEngine{knitr::knitr} 添加到 Rnw 源文档(请注意,您仍然需要 %\VignetteIndexEntry{} 作为之前)
  2. 在包描述文件中指定VignetteBuilder:knitr
  3. 如果仅需要 knitr,则在 DESCRIPTION 中添加 建议:knitr

另请参阅有关该主题的官方 R 文档

This is supported natively as of R 3.0.0, see http://yihui.name/knitr/demo/vignette/.

Instructions to use knitr as vignette engine boil down to:

  1. add %\VignetteEngine{knitr::knitr} to the Rnw source document (note you still need %\VignetteIndexEntry{} as before)
  2. specify VignetteBuilder: knitr in the package DESCRIPTION file
  3. add Suggests: knitr in DESCRIPTION if knitr is needed only for vignettes

See also the official R documentation on that topic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文