Rmarkdown 主题未在使用 R CMD build 的小插图中应用

标签 r markdown r-markdown knitr r-package

我正在尝试制作一个具有特定主题的 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/

相关文章:

r - 将 netcdf 时间变量转换为 R 日期对象

r - 操纵 slider 未出现在 'plot' 中

sql - 将查询作为变量传递给 Rmarkdown sql block

r - ggplot 中的两个散点图,两个散点图之间有箭头

html - 网络抓取 : how to include quote character in HTML node

r - knitr 模板和循环中的子文档

c# - 使用 markdown 防止脚本注入(inject)

awk - 哪些 vimrc 设置控制 markdown 中缩进 awk 代码的语法突出显示?

ggplots周围的Rmarkdown裁剪空白

R:基于字符串访问对象字段