Search code examples
rknitrdevtools

Error when building Vignette - R package development


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


Solution

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