How to build a pdf vignette in R and RStudio
Asked Answered
W

1

18

I am new to writing R packages. I'm trying to learn how to make a vignette for my package. I have created a vignettes folder with a file "getting-started.Rmd"

---
title: "WaterML Tutorial"
author: "Jiri Kadlec"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to the WaterML R package}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Quick Start

This simple example shows how to get started with the <my R package>.

To build the vignette I use the command:

devtools::build_vignettes()

Then I run Rcmd.exe INSTALL my_package, and to view my vignette I run:

browseVignettes("my_package")

However I only see the vignettes in the html and source format: I don't see the pdf option for vignettes

As you see in the screenshot, there's no "pdf" option. How do I configure my .Rmd file to create my vignette in the pdf format?

Wether answered 24/6, 2015 at 22:1 Comment(1)
Does this answer your question? #30937469 or possibly try output:pdf_document ?Stickinthemud
B
17

In your header, you are telling R to output only an html vignette in line:

output: rmarkdown::html_vignette

If you want pdf, try:

output: pdf_document

According to R packages:

Output: this tells rmarkdown which output formatter to use. There are many options that are useful for regular reports (including html, pdf, slideshows, …) but rmarkdown::html_vignette has been specifically designed to work well inside packages. See ?rmarkdown::html_vignette for more details.

So you might have a few small problems using a raw pdf.

At this time, rmarkdown does not have a output: rmarkdown::pdf_vignette option

Barman answered 24/6, 2015 at 22:21 Comment(2)
And there is no need to have a output: rmarkdown::pdf_vignette option (pdf_document will simply work). The reason for html_vignette is explained here: rmarkdown.rstudio.com/package_vignette_format.htmlScamander
Good explanation. So I see that html_vignette is the preferred format in R packages because the size is much smaller.Wether

© 2022 - 2024 — McMap. All rights reserved.