【问题标题】:pkgdown and R Markdown templatespkgdown 和 R Markdown 模板
【发布时间】:2022-12-18 14:00:34
【问题描述】:
对于包含多个 R Markdown 模板的包,是否可以将这些模板 (skeleton.Rmd) 的呈现版本作为小插图/文章包含在包文档网站中(使用 pkgdown 设置)。我想对包中可用的所有模板有一个很好的了解。
我想避免创建新的小插图,将代码从 R Markdown 模板复制/粘贴到小插图/文章。理想情况下,我只想将它们链接到模板(inst/rmarkdown/templates 目录中的skeleton.Rmd)。
关于如何实现这一目标的任何建议?
谢谢!
最初posted on 2020-08-19 on Posit Community 但没有回应。
【问题讨论】:
标签:
r
r-markdown
r-package
pkgdown
【解决方案1】:
是的,可以将 R Markdown 模板的呈现版本作为小插图或文章包含在使用 pkgdown 设置的包文档网站中。为此,您可以使用 knitr::include_graphics() 函数在插图或文章中包含 R Markdown 模板的呈现输出(HTML 或 PDF)。
下面是一个示例,说明如何使用 knitr::include_graphics() 函数在小插图或文章中包含 R Markdown 模板的渲染输出:
```{r, include = FALSE}
# Load the required packages
library(knitr)
# Define the path to the R Markdown template
template_file <- "inst/rmarkdown/templates/skeleton.Rmd"
# Define the path to the rendered output (HTML or PDF) of the R Markdown template
output_file <- "inst/rmarkdown/templates/skeleton.html"
# Include the rendered output in the vignette or article
knitr::include_graphics(output_file)
此代码使用 knitr::include_graphics() 函数在小插图或文章中包含 skeleton.Rmd R Markdown 模板的呈现输出(HTML 或 PDF)。 include_graphics() 函数将呈现的输出文件的路径作为参数,并将其包含在小插图或文章中。