Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a pdf vignette in R and RStudio

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?

like image 229
jirikadlec2 Avatar asked Jun 24 '15 22:06

jirikadlec2


People also ask

How do you make a vignette in R?

To create a package vignette in R Markdown, the easiest way is through the RStudio menu File -> New File -> R Markdown -> From Template (see Figure 16.4). Then you select “Package Vignette” from the rmarkdown package, and you will get a vignette template.

How do I create an R markdown in PDF?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

How do you find R vignettes?

Currently, only PDF versions of vignettes can be viewed. The program specified by the pdfviewer option is used for this. If several vignettes have PDF versions with base name identical to topic , the first one found is used. If no topics are given, all available vignettes are listed.


1 Answers

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

like image 66
jeremycg Avatar answered Sep 21 '22 14:09

jeremycg