I am trying to write R Package vignettes using R Markdown. I am using R Studio's package authoring tools.
I have R greater than version 3.0.
I have an .Rmd file in the vignettes
folder that contains the following text at the top:
<!--
%VignetteEngine{knitr::knitr}
%VignetteIndexEntry{An Introduction to the bootcorrelations package}
-->
I have the following in my DESCRIPTION
file:
VignetteBuilder: knitr
Suggests: knitr
When I clean and build or build and reload the package in RStudio, the vignette source is displayed, but not the HTML (i.e., there's no HTML file in inst/man
).
How can I get RStudio to automatically create the HTML from an R Markdown Vignette?
I've read through Yihui's post on R Package Vignettes with Markdown and it suggests using a makefile, but this more recent documentation about knitr vignettes suggests that the makefile is no longer required.
I also realise that I could manually create the HTML vignette with a command like this:
library(knitr)
knit(input='vignettes/foo.Rmd', output='inst/doc/foo.md')
library(markdown)
markdownToHTML('inst/doc/foo.md', 'inst/doc/foo.html')
A reproducible example:
Vectorize(dir.create)(c("test", "test/R", "test/man", "test/vignettes"))
cat(
'Package: test
Title: Test pkg
Description: Investigate how to auto-compile markdown vignettes
Version: 0.0-1
Date: 2015-03-15
Author: Jeromy Anglim
Maintainer: Jeromy Anglim <[email protected]>
Suggests: knitr
License: Unlimited
VignetteBuilder: knitr',
file = "test/DESCRIPTION"
)
cat(
'---
title: "Introduction"
author: "Jeromy Anglim"
date: "`r Sys.Date()`"
output: html_document
---
<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Introduction}
-->
# Introduction
A sample vignette!
```{r}
1 + 1
```',
file = "test/vignettes/intro.Rmd"
)
cat(
"#' Nothing
#' This function is only needed so that roxygen generates a NAMESPACE file.
#' @export
nothing <- function() 0",
file = "test/R/nothing.R"
)
library(roxygen2)
library(devtools)
roxygenise("test")
build("test")
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…