knitr does not build vignette - r

I am writing a package vignette with Rmarkdown. I tried to follow all the tuto from Hadley, Yihui, Rstudio cheat sheet... but I still don't manage to embed the vignette correctly.
For now I have a .Rmd file which compiles fine by pressing Rstudio button "knit". However:
devtools::build_vignettes() returns NULL
building a source package and running R CMD INSTALL does nothing to the /vignettes folder
I have checked the box use roxygen for vignette in Rstudio parameters
when I compile with Rstudio, it saves the .pdf output in a wired temp directory:
Output created:
/private/var/folders/53/l9bfpvgj4y7brgnjwym34kph0000gn/T/RtmpydyKqk/preview-ffc141c28b47.dir/mistral-vignette.pdf
Since my vignette is pretty long to build I would be happy to just include the .pdf output
The YAML input:
---
title: "Using mistral for reliability analysis"
author: "Clément Walter"
date: '`r Sys.Date()`'
output: rmarkdown::pdf_document
vignette: >
%\VignetteIndexEntry{Using mistral for reliability analysis}
%\VignetteEngine{rmarkdown::render}
%\VignetteEncoding{UTF-8}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{ }
---
In the DESCRIPTION file, I have added:
VignetteBuilder: knitr
Suggests: knitr, rmarkdown

Related

How to define reference_docx in rmarkdown file using pandoc 2.1

I downloaded the latest version of RStudio and then upgraded to pandoc 2.1 because I wanted to control the custom table setting in the output .docx file.
However, in the previous version of pandoc with RStudio (1.9) the following YAML produced the correct .docx file:
---
title: "Report"
author: "Me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
word_document:
reference_docx= ../support/word/rmd_styles.docx
toc: true
fig_caption: true
---
But when I upgraded to pandoc 2.1 (and verified it in RStudio console with):
> rmarkdown:::find_pandoc()
> as.list(rmarkdown:::.pandoc)
$version
[1] ‘2.1’
The reference to the .docx file in the YAML above no longer works and I get the following error:
--reference-docx has been removed. Use --reference-doc instead.
Try pandoc.exe --help for more information.
So when I switch reference_docx to reference_doc (not sure if that is correct?) I get the following error:
--reference-docx has been removed. Use --reference-doc instead.
Try pandoc.exe --help for more information.
Error: pandoc document conversion failed with error 2
In addition: Warning message:
running command '"C:/Users/Prevost~1.PRE/AppData/Roaming/local/bin/pandoc" +RTS -K512m -RTS Report.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output Report.docx --table-of-contents --toc-depth 3 --highlight-style tango --reference-docx "..\support\word\rmd_styles.docx"' had status 2
Execution halted
Hopefully I am just using the incorrect syntax in the YAML but I'm not sure what's going on. Any help is greatly appreciated!
I was having this issue with the rmarkdown package 1.6 and I solved it by updating to rmarkdown 1.8. You may do so by executing the following code
install.packages('rmarkdown')
and the loading it by executing
library(rmarkdown)

Error Message "latex-engine has been removed" when knitting to pdf

I'm working on a Mac and have an R script file that I would like to compile to a PDF document. I have inserted the following at the top for the output:
#' beamer_presentation:
#' toc: yes
#' slide_level: 2
#' latex_engine: xelatex
Once I press command+shift+k to knit this file, I get the following error message:
--latex-engine has been removed. Use --pdf-engine instead.
Try pandoc --help for more information.
Error: pandoc document conversion failed with error 2
Execution halted
I did download mactex and pandoc 2.0.1.1. from the pandoc website. Some of my colleages are able to knit the file, so I'm rather sure that the content is not the issue.
This issue has been reported and fixed in the current development version of rmarkdown, which you can install with:
if (!require("devtools")) install.packages("devtools")
devtools::install_github("rstudio/rmarkdown")

Rmd Vignette fails in devtools::check because of missing package

I'm developing an R package. The vignette is an .Rmd that loads ggplot using library(ggplot2). I'm trying to get it to pass checks. The checks are failing to build the Vignette because it says that that ggplot2 is missing. Following Hadley's advice here and other advice here, I've done the following to try to get the check to install the packages that are only dependencies for the vignette:
Added the packages to the the Suggests: field in the DESCRIPTION file
Added the packages to the top of the vignette %\VignetteDepends{ggplot2} in the same block where the other commands go. So for example the header for the Vignette reads:
---
title: "VIGNETTE"
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
default
vignette: >
%\VignetteIndexEntry{VIGNETTE}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
%\VignetteDepends{ggplot2}
---
The vignette works fine when I install ggplot2. However, it doesn't know to install the dependencies without manually installing it. This leads to both devtools::build_vignettes() and devtools::check() failing with the following error:
Error: processing vignette 'VIGNETTE.Rmd' failed with diagnostics:
there is no package called 'ggplot2'
Any advice? Thank you.

knitr .Rmd vignettes do not appear with vignette()

In a package I'm developing with R Studio, I create vignettes via devtools::use_vignette("mydoc.Rnw"), which gives a standard vignette header like
---
title: "Title"
author: "Michael Friendly"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
I have followed all the instructions in http://yihui.name/knitr/demo/vignette/ and http://r-pkgs.had.co.nz/vignettes.html. The vignettes are listed on the CRAN page for the package, yet they seem inaccessible in an R session with the package loaded.
> browseVignettes("matlib")
No vignettes found by browseVignettes("matlib")
> library(tools)
> names(vignetteEngine(package = 'matlib'))
Error in getEngine(name, package) :
None of packages ‘matlib’ have registered vignette engines
I know that other packages with knitr-processed .Rmd vignettes are accessible from the package, but can't figure out why mine are not.
What is missing?
My vignettes/ directory contains only the .Rmd files (no PDFs), but that seems the same as, e.g., https://github.com/yihui/knitr/tree/master/vignettes.
Note devtools does not build vignettes by default when you devtools::install() (same thing for some install_* functions like install_github()) a package from a directory. You have to specify the argument build_vignettes = TRUE when you install the package. Currently there is no way to build vignettes using devtools if you just use the RStudio button Build & Reload. You have to Build Source Package, and run R CMD INSTALL on the tarball. Or run devtools::install(build_vignettes = TRUE) in the R console.
Well, I find a dark magic which can work around this situation.
From Configure Build Tools..., RStudio allows us to custom options for R CMD INSTALL when you click the Build & Reload button. In current implementation, it behaves like running R CMD INSTALL [options] pkg at the parent directory of the package directory.
It turns out that these options can be arbitrary strings, even including ;, thus enable us to run bash commands.
For example, we can specify -v; cd pkg; cp vignettes/*html inst/doc; R CMD INSTALL --no-multiarch --with-keep.source .; echo
In this way, -v nullify RStudio's R CMD INSTALL. Then we can copy built html files in vignette/ to inst/doc/ before we install the package using our own R CMD INSTALL. (cd pkg; frees us from type package name multiple times in subsequent commands. echo nullify the package name appended by RStudio.
I know there are many drawbacks in this trick, such as hard-coding package name which is error prone if the package name is changed latter.
Use it at your own risk.
Hope RStudio will comes out a elegant solution soon.
On my end, using devtools::install(build_vignettes = TRUE) would solve the vignettes problem: browseVignettes("mypackage") would work normally. But every time I tried to open a help file ?myfunction, there would be an error message:
Error in fetch(key) : lazy-load database
'/Library/Frameworks/R.framework/Versions/3.6/Resources/library/mypackage/help/mypackage.rdb' is corrupt
The safest way to solve both issues, in my opinion, is to do R CMD build mypackage and R CMD INSTALL mypackage.1.0.tar.gz.

Error: pandoc document conversion failed with error 43 Windows 7 R studio

I have search the answers in the forum, but they dont seem to work.
I am knitting a pdf document in Rstudio using the knitr package. I am using Windows 7 and Rstudio.
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" PA1_template.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output PA1_template.pdf --template "C:\R\Library\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43
Execution halted
Thanks,
Luis
I had the same issue but on Linux using the latest rmarkdown package and pandoc 1.13. In essence it seems like pdflatex does not work with the output generated by pandoc - you need to replace the latex-engine pdflatex with xelatex (part of TeXLive)
For rmarkdown my solution was to edit the file
rmarkdown/templates/tufte_handout/resources/tufte-common.def
and replace the line
\typeoutbool{pdfatex}{#tufte#pdf}
with
\typeoutbool{xelatex}{#tufte#pdf}
Then xelatex will be used instead of pdflatex to generate pdf's with rmarkdown
I faced the same issue, here are the steps I took to solve the problem:
install devtools in Rstudio (install.packages(devtools))
install rmarkdown (devtools::install_github("rstudio/rmarkdown"))
fix the files tufte-common.def and tufte-handout.tex in ~/R/x86_64-pc-linux-gnu-library/3.2/rmarkdown/rmarkdown/templates/tufte_handout/resources/
If the rmarkdown installation did not go smoothly this way then do it like this (devtools::install_github("git://github.com/rstudio/rmarkdown"))
In tufte-common.def do the following:
Add this line
\typeoutbool{xelatex}{#tufte#pdf}
uncomment this line
\typeoutbool{xelatex}{#tufte#xetex} remember % is used to uncomment latex
Add the following lines in tufte-handout.tex:
% UTF encoding
\usepackage[utf8]{inputenc}
When I tried to compile a document I still got the following error (! Font \XeTeXLink#font=pzdr at 0.00002pt not loadable: Metric (TFM) file or ins talled font not found.), I tackled it by installing texlive-fonts-recommended:
sudo apt-get install texlive-fonts-recommended
I had a similar problem. Telling knitr where to find the pdf-engine was necessary even though I had it on the windows path. Here is the header of the knitr.Rmd-document, that solved the problem for me:
---
title: "XXX"
author: "XXX"
date: '2016-11-28'
output:
pdf_document:
keep_tex: yes
pandoc_args:
- --latex-engine
- C:/Program Files/MiKTeX 2.9/miktex/bin/x64/pdflatex.exe
toc: yes
---

Resources