Error when building Vignette - R package development - r

My apologies in advance if this is an obvious question but I have searched both stack overflow and what have been otherwise very useful resources like R packages by Hadley Wickham or this blog and can not find an answer.
My issue occurs when trying to run build_vignettes() on my developed R package (myPackage). The vignette for the package (myPackage.Rmd) will create as expected using knit in RStudio but when I run build_vignettes(), I get the following error:
> devtools::build_vignettes()
Building cosni vignettes
--- re-building ‘myPackage.Rmd’ using rmarkdown
--- finished re-building ‘myPackage.Rmd’
Error: Directory '✓ Setting active project to \'path/to/package/directory/'' does not exist.
The top of my myPackage.Rmd file is:
---
title: "A title"
date: "`r Sys.Date()`"
author: "Name"
output:
html_document:
toc: true
toc_float: true
number_sections: true
theme: "paper"
pdf_document:
toc: true
vignette: >
%\VignetteIndexEntry{A title}
%\VignetteEngine{knitr::rmarkdown}
\usepackage[utf8]{inputenc}
---
This file is located in the vignettes folder of my package folder. There are also 3 png images in this folder which are called in the myPackage.Rmd file as follows:
```{r, echo=FALSE, out.width = '98%', out.height='98%'}
knitr::include_graphics("an_image.png")
```#
Otherwise the vignette only contains text.
The package will run and I can install it locally with either devtools::build() or
devtools::install(build_vignettes = TRUE) they will work but then when I run browseVignettes("myPackage") and click on the HTML, source or R code I get the following error:
Not Found
The requested URL /library/myPackage/doc/myPackage.html was not found on this server.
Also, in the package's DESCRIPTION file I have included the following:
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
----------- EDIT --------------
Through repeatedly trying to get the devtools::build_vignettes to work I have noted that sometimes I get the following error rather than the first I mentioned:
> devtools::build_vignettes()
Building cosni vignettes
--- re-building ‘myPackage.Rmd’ using rmarkdown
--- finished re-building ‘myPackage.Rmd’
Error in if (dir_exists(path %||% "") && is_in_proj(path)) { :
missing value where TRUE/FALSE needed

I solved the second error you get updating packages devtools and usethis.

Related

Bibliography causes rmarkdown::render() to fail

trying to render my rmarkdown into a MS Word, if I add a bibliography I get this error:
pandoc-citeproc: when expecting a product (:*:), encountered Object instead
Error running filter pandoc-citeproc:
Filter returned error status 1
Error: pandoc document conversion failed with error 83
These are the headers of my .rmd file:
title: XXX.
author: "Angelo D'Ambrosio"
date: "10/8/2020"
delete_merged_file: true
bibliography: references.bib
output:
word_document:
reference_docx: style.docx
pandoc_args: ['-F', 'pandoc-crossref']
toc: yes
---
I read around that it could be a matter of pandoc versions. I updated my pandoc with brew, since the RStudio one is too old and couldn't work with pandoc-crossref.
UPDATE:
It is indeed related to pandoc version. To make pandoc work with pandoc-crossref I need to force rmarkdown to use the version of pandoc I downloaded with rmarkdown::find_pandoc(dir = "/usr/local/Cellar/pandoc/2.10.1/bin"). But then this version don't like pandoc-citeproc. So if I use rstudio default pandoc I get pandoc-citeproc and if I use the one I downloaded I get pandoc-crossref. How can I get both??

Very simple .rmd --> beamer_presentation; still cannot get rid of "Option clash for package xcolor"

I cannot compile to a pdf-beamer from a very simple minimal example (below), with no packages.
I click - Knit - Knit to pdf
(Note this is not a duplicate of previous posts, because those all involved using Kable; I am not using it; fresh restart not calling any packages here)
I tried with and without classoption: table
Knit to html works just fine.
Restarted Rstudio; no improvement
---
title: "Untitled"
author: "Test"
date: "20 novembre 2018"
classoption: table
output:
beamer_presentation:
keep_tex: yes
---
# Test nothing
blah
```
Throws error: ! LaTeX Error: Option clash for package xcolor.
I want it to compile a beamer pdf slide show, of course.
I've put the log file here
My default.beamer (stored at /Users/yosemite/.pandoc/templates/default.beamer I think) is linked HERE

VignetteBuilder entry forcing "prebuild" of index when releasing R package to CRAN

I am building a new R package. I have the same problem given here. I have also gone through the links suggested. But I keep getting rejections because the note says
"Package has a VignetteBuilder field but no prebuilt vignette index.
So please add a vignette index."
I went to the CRAN package list for latest packages and then went through the code of packages like hyfo , mldr and few others which have all released in the past few days. None of them have an index file. But, my code below is getting rejected. My code does not show any warnings or errors or NOTES when I run devtoold::check(). I am not getting any warnings/errors on devtools:build_win() as well.
Any ideas on what I am missing?
I am using R version 3.2.2 on windows. My DESCRIPTION file which has the following
Package: Mypackage
Suggests:
knitr,
rmarkdown,
R.rsp
VignetteBuilder: knitr
RoxygenNote: 5.0.1
In the vignettes directory, the file Mypackage.Rmd has
title: "Mypackage"
author: "blah"
date: "`r Sys.Date()`"
output:
html_document:
fig_width: 7
fig_height: 6
fig_caption: true
vignette: >
%\VignetteIndexEntry{Mypackage}
%\VignetteEngine{R.rsp::asis}
%\VignetteEncoding{UTF-8}
---
## Introduction
The contents of the vignette
How do I create the vignette index or how do I make this NOTE disappear?
Ok 2 issues with this.
Vignette Index
First you need to have a build/vignette.rds file listing the vignettes. You can check this with:
> readRDS("build/vignette.rds")
File Title PDF R Depends Keywords
1 Mypackage.Rmd Mypackage Mypackage.html Mypackage.R
2 MyGuide.Rmd MyGuide MyGuide.html MyGuide.R
Here the "Title" column is the title from \VignetteIndexEntry{Mypackage} and the rest are names of the files.
Notice there 2 additional blank fields "Depends" and "Keywords" here. You can create a new data.frame if you don't have one already.
file <- data.frame(matrix(NA, 1, 6))
colnames(file) <- c("File", "Title", "PDF", "R", "Depends", "Keywords")
file[1,] <- c("MyPackage.Rmd", "MyPackage", "MyPackage.html", "MyPackage.R", "", "")
saveRDS(file, file = "vignette.rds")
To add a row with a new vignette to an existing data.frame:
file <- readRDS("build/vignette.rds")
file[3,] <- c("import_reactome.Rmd", "Importing pathways from databases", "import_reactome.html", "import_reactome.R", "", "")
saveRDS(file, file = "vignette.rds")
Generating static HTML vignettes
These vignettes are not generated on CRAN and must be pre-generated before upload. Run knitr::knit in RStudio on an Rmd file is the easiest way to do this. Then copy the output file to vignettes/MyPackage.html. You can also skip building vignettes by copying it to inst/doc/MyPackage.html.
You can add this line to return an HTML file when building the package.
title: "Mypackage"
author: "blah"
date: "`r Sys.Date()`"
output:
html_document:
fig_width: 7
fig_height: 6
fig_caption: true
keep_html: true ### <- add this line
vignette: >
%\VignetteIndexEntry{Mypackage}
%\VignetteEngine{R.rsp::asis}
%\VignetteEncoding{UTF-8}
---
You do not need a markdown file. You can add the following line to .Rbuildignore to prevent it being included.
^vignettes/plot_directed.md#
Passing checks with devtools
For more details see the Static_PDF_and_HTML_vignette from R.rsp. This describes how to use the R.rsp::asis engine.
The key part is that you need to have both a vignettes/MyPackage.html and vignettes/MyPackage.html.asis file. The vignettes/MyPackage.html.asis file only needs 3 lines, the rest are optional.
%\VignetteIndexEntry{MyPackage}
%\VignetteEngine{R.rsp::asis}
%\VignetteEncoding{UTF-8}
Once these files are included the devtools::install(build_vignettes = TRUE) and devtools::check() should run as expected.

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:
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

Enforce PDF package vignette with knitr

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.

Resources