用knitr强制执行PDF包插图 [英] Enforce PDF package vignette with knitr
问题描述
我的包装上有一个小插图,当使用Rscript -e 'rmarkdown::render("tmod.rmd")'
进行编译时,该小插图将编译为一个漂亮的PDF.但是,当我编译并安装该软件包时,启动R并键入vignette("mypackagename")
,将打开一个浏览器窗口,显示难看的HTML,没有标题,没有目录和引用.
I have a vignette for my package which compiles to a nice PDF when compiled with Rscript -e 'rmarkdown::render("tmod.rmd")'
. However, when I compile and install the package, start R and type vignette("mypackagename")
, a browser window opens with ugly looking HTML, without a title, without a table of contents and without references.
但是,如果我在创建包之前将小插图手动编译为pdf,则显示效果很好.
However, if I compile the vignette manually to pdf before creating the package, it shows up just fine.
出了什么问题?为什么在编译软件包时不能自动生成PDF?
What went wrong? Why is my PDF not generated automatically when I compile the package?
在markdown文件头中,
In the markdown file header, I have
---
title: "foo foo foo"
author: "Foofooary Finer"
date: "`r Sys.Date()`"
output:
pdf_document:
vignette: >
%\VignetteIndexEntry{FooFoo}
%\VignetteKeyword{foo}
%\VignetteEngine{knitr::knitr}
%\SweaveUTF8
\usepackage[utf8](inputenc)
abstract: |
foo foo foo foo foo
toc: yes
bibliography: bibliography.bib
---
我在包裹DESCRIPTION文件中
In the package DESCRIPTION file, I have
VignetteBuilder: knitr
Suggests: knitr
推荐答案
当我在knitr谷歌小组上问同样的问题时,谢益辉(knitr的作者)回答:
When I asked the same question on the knitr google group, Yihui Xie (author of knitr) replied:
使用小插图引擎knitr :: rmarkdown代替knitr :: knitr.
Use the vignette engine knitr::rmarkdown instead of knitr::knitr.
我不完全确定我理解为什么,但是它可以工作. 此处是链接,用于讨论Google编织小组.
I'm not entirely sure I understand why, but it works. Here is a link to discussion on the knitr google group.
这篇关于用knitr强制执行PDF包插图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!