I'm confused as to why my R package's vignette is in HTML on CRAN and not a pdf.
I followed the advice at Enforce PDF package vignette with knitr and used
%\VignetteEngine{knitr::rmarkdown}
to generate the vignette, but there it is, a pdf. The full header of one of the files is
---
title: "wCorr Formulas"
author: "Paul Bailey, Ahmad Emad, Ting Zhang, Qingshu Xie"
date: '`r Sys.Date()`'
output:
pdf_document: default
vignette: |
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{wCorr Formulas}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
---
you can see the whole package at https://github.com/cran/wCorr or, before it gets built at https://github.com/ahmademad/wCorr
You are including copies of the HTML output (presumably from an earlier version) in inst/doc.
This might not have been intentional; I believe devtools::build_vignettes might do it to work around a bug in R: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17416. But there are better workarounds, e.g. described here: https://github.com/yihui/knitr/issues/1540 .
Related
I try to use a Unicode character (U+2685) in math mode with Bookdown, I set mathfont: STIX Two Math (which contains this character), yet the resulting PDF contains an empty space. (At the same time the HTML is correct.)
What's wrong here?
(My best guess is that I should perhaps use the unicode-math package. Unfortunately I can't include it in the preamble.tex as it is incompatible with the mathspec, but at the same time I see no way to get rid of mathspec; it seems to be hardcoded in Bookdown that mathspec is usepackaged when xelatex is used.)
Minimal reproducible example (showing index.Rmd, all other file is the same as with the default new project created with RStudio):
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
mainfont: STIX Two Math
mathfont: STIX Two Math
---
# Prerequisites
In text: ⚀.
In math mode: $⚀$.
This is how the result looks like:
This issue is now solved (after an update to rmarkdown), see here.
I'm trying to build a book with R/bookdown and I'm facing a problem when producing a html version using tufte_html_book or html_book:
Error in split_chapters(output, page_builder, number_sections, split_by, :
The document must start with a first (#) or second level (##) heading
The book is correctly produced in gitbook or tufte_book2 output.
The document has four files index.Rmd, 01-Chap1.Rmd, 02-Chap2.Rmd, 03-Chap3.Rmd. I like to keep things clear, so index.Rmd only contains the YAML headers, plus some R code but no heading, which is probably what yields the error. Is there a way to make the html outputs of bookdown behave similarly to gitbook or pdf output?
Here is a small reproducible example:
Index.Rmd:
---
title: "Tufte Handout"
subtitle: "An implementation in R Markdown"
author: "JJ Allaire and Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::tufte_html_book:
toc: yes
bookdown::tufte_book2:
toc: yes
---
```{r setup1, include=FALSE}
library(tufte)
# invalidate cache when the tufte version changes
knitr::opts_chunk$set(tidy = FALSE, cache.extra =
packageVersion('tufte'))
options(htmltools.dir.version = FALSE)
```
01-Chap1.Rmd
# Introduction
The Tufte handout style is a style that Edward Tufte uses in his books and handouts. Tufte's style is known for its extensive use of sidenotes, tight integration of graphics with text, and well-set typography. This style has been implemented in LaTeX and HTML/CSS^[See Github repositories [tufte-latex](https://github.com/tufte-latex/tufte-latex) and [tufte-css](https://github.com/edwardtufte/tufte-css)], respectively. We have ported both implementations into the [**tufte** package](https://github.com/rstudio/tufte). If you want LaTeX/PDF output, you may use the `tufte_handout` format for handouts, and `tufte_book` for books.
For HTML output, use `tufte_html`. These formats can be either specified in the YAML metadata at the beginning of an R Markdown document (see an example below), or passed to the `rmarkdown::render()` function. See #R-rmarkdown more information about **rmarkdown**.
I'm answering my own question.
The difference in behaviour between gitbook and (tufte_)html_book is in the split_by argument, which is split_by="chapter" in gitbook and split_by="section" in (tufte_)html_book. Adding split_by: chapter to the bookdown::tufte_html_book: yaml section allows to build the html without error.
I'm trying to run inline R code in the YAML front matter before getting rmarkdown to run the file. However it isn't working for me. Here's an example:
---
title: "**Title**"
classoption: xcolor=dvipsnames
output:
beamer_presentation:
slide_level: 2
pandoc_args: [
"--bibliography", "`r paste('path/to/bib')`"
]
---
<!-- slide 1 -->
## Intro ##
Which throws an error:
pandoc-citeproc: could not find `r paste('path/to/bib')`
This is a simple example, but highlights my main problem. How do I get rmarkdown to run the inline R code in the YAML front matter?
It is a similar problem to these questions:
Manipulate RMarkdown metadata from within R code chunks
YAML current date in rmarkdown
This is how I solved this. I knit from RStudio. Curiously, I had to use one solution for the date and csl fields and a different solution for the bibliography field. !expr did not work in the date or csl lines (for me). And quoted r code didn't work in the bibliography line (for me). I have the bibliography and csl files in a package (inst/docs folder). rmarkdown files, which are not part of that package, use those.
---
title: "Title"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output: html_document
bibliography: !expr system.file("docs", "my.bib", package = "MyPackage")
csl: '`r system.file("docs", "my.csl", package = "MyPackage")`'
---
# Introduction
Yada yada [#MyRef04].
# References
my.bib is the BibTex file with MyRef04. csl is the style file
This is a situation where one person maintains a package which has data, code, bibliography, etc. Others, potentially unknown to the package writer, install that package from GitHub and write or run rmarkdown files that use the package. The users almost certainly do not use Git or GitHub and I don't want them to have to download any extra files after installing the package from GitHub.
Update: After posting the above, I happened to install markdown from GitHub because I needed something in the development version. With version ‘1.7.5’ of rmarkdown on GitHub you can use r code in the bibliography line:
---
title: "Title"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output: html_document
bibliography: '`r system.file("docs", "my.bib", package = "MyPackage")`'
csl: '`r system.file("docs", "my.csl", package = "MyPackage")`'
---
To install rmarkdown from GitHub
library(devtools)
install_github("rstudio/rmarkdown")
So I found a round about way of getting what I wanted. Rmarkdown I don't think allows R expressions/commands in the YAML, probably for a good reason. What I ended up doing was putting all the output yaml commands in a file called _output.Ryaml like so:
beamer_presentation:
slide_level: 2
includes:
in_header: "src/preamble.tex"
pandoc_args: [
"--bibliography", "`r paste('path/to/bib')`",
"--variable", "classoption:xcolor=dvipsnames",
"--variable", "fontsize:9pt"
]
Then in the main slides.Rmd file, was something like:
---
title: "**Title**"
author: Luke
---
<!-- slide 1 -->
## Intro ##
Then, I can generate the slides using the R code (which I put into a Makefile):
knitr::knit('_output.Ryaml', '_output.yaml')
rmarkdown::render('slides.Rmd')
unlink('_output.yaml')
Seems to be working well enough. If anyone's got a better idea, let me know!
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:
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?
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
I have a vignette for my package which compiles to a nice PDF when compiled with Rscript -e 'rmarkdown::render("tmod.rmd")'. However, when I compile and install the package, start R and type vignette("mypackagename"), a browser window opens with ugly looking HTML, without a title, without a table of contents and without references.
However, if I compile the vignette manually to pdf before creating the package, it shows up just fine.
What went wrong? Why is my PDF not generated automatically when I compile the package?
In the markdown file header, I have
---
title: "foo foo foo"
author: "Foofooary Finer"
date: "`r Sys.Date()`"
output:
pdf_document:
vignette: >
%\VignetteIndexEntry{FooFoo}
%\VignetteKeyword{foo}
%\VignetteEngine{knitr::knitr}
%\SweaveUTF8
\usepackage[utf8](inputenc)
abstract: |
foo foo foo foo foo
toc: yes
bibliography: bibliography.bib
---
In the package DESCRIPTION file, I have
VignetteBuilder: knitr
Suggests: knitr
When I asked the same question on the knitr google group, Yihui Xie (author of knitr) replied:
Use the vignette engine knitr::rmarkdown instead of knitr::knitr.
I'm not entirely sure I understand why, but it works. Here is a link to discussion on the knitr google group.