我正在尝试制作一个具有特定主题的 html 包小插图,例如来自 prettydoc (` https://github.com/yixuan/prettydoc/blob/master/vignettes/hpstr.Rmd) 的 hpstr 主题。
如果我手动构建小插图:
rmarkdown::render('vignettes/hpstr.Rmd', output_format='prettydoc::html_pretty')
主题已正确应用。但是,当我使用标准构建过程时,例如:
git clone https://github.com/yixuan/prettydoc.git
cd prettydoc
R CMD build .
R CMD INSTALL prettydoc_0.2.1.tar.gz
然后,在 R 中:
> library('prettydoc')
> vignette('hpstr')
主题根本没有渲染,它看起来像一个普通的 html_output
。
小插图顶部的 yml 如下所示:
---
title: "Creating Pretty Documents from R Markdown"
subtitle: "The HPSTR Theme"
author: "Yixuan Qiu"
date: "`r Sys.Date()`"
output:
prettydoc::html_pretty:
theme: hpstr
highlight: github
vignette: >
%\VignetteIndexEntry{Creating Pretty Documents from R Markdown - The HPSTR Theme}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
并且在 DESCRIPTION
文件中指定了 vignette builder:
VignetteBuilder: knitr, rmarkdown
所以看起来 vignette builder 不是 rmarkdown::render
。
如何使用 R CMD build
自动应用主题?
最佳答案
如果 pandoc 未在系统级别安装或太旧,则可能会发生这种情况,而 RStudio 附带其自己的 pandoc 版本。因此,RStudio 中的渲染成功,而 R CMD build
失败。可能的解决方案:
- 在系统级别安装或更新 pandoc
- 使 RStudio 附带的 pandoc 在系统级别可用
- 在 RStudio 中构建包(@YihuiXie 建议)
关于Rmarkdown 主题未在使用 R CMD build 的小插图中应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50394988/