Vignette output missing despite no errors - r

I am writing an R package with this vignette title:
---
title: "Adaptive non-parametric learning"
author: "..."
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Adaptive non-parametric learning}
%\VignetteEngine{knitr::rmarkdown_notangle}
%\VignetteEncoding{UTF-8}
---
I added rmarkdown_notangle to avoid running the vignette on CRAN, as the full vignette will take an hour to run (even though now I am testing and it takes 2 minutes).
I compile the package with:
Rscript -e "devtools::document();devtools::check();devtools::build();devtools::install();"
The output shows:
...
─ installing the package to build vignettes
✔ creating vignettes (1m 48.8s)
...
✔ checking files in ‘vignettes’ ...
...
✔ checking for unstated dependencies in vignettes ...
✔ checking package vignettes in ‘inst/doc’
✔ checking re-building of vignette outputs (1m 47.9s)
...
─ installing the package to build vignettes
✔ creating vignettes (1m 49.5s)
...
** installing vignettes
** testing if installed package can be loaded
* DONE (PosteriorBootstrap)
Reloading attached PosteriorBootstrap
But the doc/ directory is empty, the inst/doc directory does not exist, and when I import the package, no vignettes are installed:
> library(PosteriorBootstrap)
> browseVignettes(package="PosteriorBootstrap")
No vignettes found by browseVignettes(package = "PosteriorBootstrap")
> vignette("Adaptive Non-parametric learning")
Warning message:
vignette ‘Adaptive Non-parametric learning’ not found
I found this thread that suggests using %\VignetteEngine{knitr::rmarkdown}, which I use, and install_github(..., build_vignettes=TRUE), which I don't since I build it locally.
Where is the vignette output?

One solution is to change the default build_vignettes = FALSE in devtools::install():
devtools::install(build_vignettes = TRUE)
Then do browseVignettes(package = "package_name") to show the vignettes, e.g. on a browser if you use R on the command line.
I found the solution from a comment in the thread I quoted, which suggested the same solution for devtools::install_github().
I could not find the vignette output created by devtools::check() and devtools::build().

Related

Cannot install vignette from an R package on GitHub

I coded an R package that is hosted on my GitHub. I included a vignette, and I can install the package and load the vignette without any issue from R and RStudio by doing:
devtools::install_github("rosalieb/serac", build_vignettes = TRUE)
library(serac)
vignette("serac")
However, I have a few colleagues who cannot install the vignette (the only way they can download the package is by doing devtools::install_github("rosalieb/serac") (default of build_vignettes is FALSE).
It works if they use RStudio, but not in 'regular' R.
I encourage people to use RStudio, but I cannot force them, and eventually, I do not understand why it would work in 'regular' R for me but not for them.
They tried to install pandoc, knitr, Rtools - none of these worked.
Here is the error message when my colleague tries to install the package with the vignette:
v checking for file 'C:\Temp\RtmpO8YwVb\remotesf9842f1431\rosalieb-serac-46a3587/DESCRIPTION'
- preparing 'serac':
checking DESCRIPTION meta-information ...
checking DESCRIPTION meta-information ...
v checking DESCRIPTION meta-information
- installing the package to build vignettes
creating vignettes ...
creating vignettes ...
E creating vignettes (4.9s)
--- re-building 'serac.Rmd' using rmarkdown
Error: processing vignette 'serac.Rmd' failed with diagnostics:
Pandoc is required to build R Markdown vignettes but not available. Please make sure it is installed.
--- failed re-building 'serac.Rmd'
RESUME : le traitement du fichier suivant a échoué :
'serac.Rmd'
Erreur : Vignette re-building failed.
Exécution arrêtée
Erreur : Failed to install 'serac' from GitHub:
System command 'Rcmd.exe' failed, exit status: 1, stdout & stderr were printed
Thanks in advance for your help!
The message indicates that rmarkdown::render can't find Pandoc.
It looks for it in three places: in the directory specified by the RSTUDIO_PANDOC environment variable, in directories on the PATH, in the directory opt/pandoc in the user's home directory. So your colleagues who have installed it should make sure it is available in one of those locations. They can see the current values of the environment variables by running
Sys.getenv("PATH")
and
Sys.getenv("RSTUDIO_PANDOC")
Temporary changes can be made using
Sys.setenv(RSTUDIO_PANDOC="/path/to/pandoc/directory")
This needs to happen in the session that is trying to install the package and build the vignette, not in the vignette itself.
How to make permanent changes to those values depends on the details of what system they are running.

Can't disable vignette build when using devtools

When running
==> devtools::check(args = c('--no-build-vignettes','--no-vignettes'))
from RStudio the vignettes are still being build:
...
v checking DESCRIPTION meta-information ...
- installing the package to build vignettes (1.4s)
creating vignettes ...
I configured the Build tools according to:
https://support.rstudio.com/hc/en-us/articles/200486518-Customizing-Package-Build-Options
Should including
--no-vignettes do not run R code in vignettes
--no-build-vignettes do not build vignette outputs
not disable the vignette build?
I think you want build_args, which is for arguments passed while building the package, not args which is for arguments passed while checking.

Loading R package in vignette for the package itself

I am currently building an R package, call it mypackage. I generated a package vignette using devtools::use_vignette("my-vignette"), and filled in my-vignette with content. Of course, because it is a package vignette, I need to demonstrate the use of the functions and data contained in this package itself. However, I'm having issues loading the package and its contents when knitting the vignette.
All of the code chunks in the vignette run without error on my local computer, even after restarting R and clearing the workspace. However, when I attempt to build the package using devtools::build(), the build fails with:
Error in library(mypackage): there is no package called `mypackage` Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> library Execution halted
The full output in the Console from devtools::build() is:
* checking for file ‘/path/to/mypackage/DESCRIPTION’ ... OK
* preparing ‘mypackage’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ... ERROR
Quitting from lines 39-44 (my-vignette.Rmd)
Error: processing vignette 'my-vignette.Rmd' failed with diagnostics:
'my_function' is not an exported object from 'namespace:mypackage'
Execution halted
devtools::document() runs without error, but devtools::build_vignettes() aparently reaches a different error where it cannot use a specific function (but seems to be able to load the package itself):
> devtools::build_vignettes()
Building mypackage vignettes
Moving basic-mypackage-vignette.html, basic-mypackage-vignette.R to inst/doc/
Copying basic-mypackage-vignette.Rmd to inst/doc/
> devtools::build()
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD build \
'/path/to/mypackage' --no-resave-data --no-manual
* checking for file ‘/path/to/mypackage/DESCRIPTION’ ... OK
* preparing ‘auctestr’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ... ERROR
Quitting from lines 39-44 (my-vignette.Rmd)
Error: processing vignette 'my-vignette.Rmd' failed with
diagnostics:
could not find function "my_function"
Execution halted
Error: Command failed (1)
> devtools::document()
Updating mypackage documentation
Loading mypackage
I assume this is because the package itself does not exist in my R library; I am just loading that package using devtools::load_all() when doing development. How can I get around this and load my package in order to use its functions and data in the package vignette? Specifically, how can I make the package in its functions available to whatever environment knitr is using to knit the vignette?
I have seen other package vignettes load the package directly using library() without issue; for example, in the stringr vignette.
I hope readers can evaluate this without a fully reproducible example; reproducing the entire example is difficult because it requires a full R package directory structure that is difficult to replicate or share here.
I do load directly my package in my vignettes (library(my_package)).
But considering your error, it might not be the problem...
Can you make sure that my_function is indeed exported. You should add the following code ate the end of the documentation of your function.
#' #export
I added a chunk
```{r, include=FALSE}
devtools::load_all(".")
```
at the beginning of the vignette to work around the problem.
However, this doesn't fix the actual problem, as this should not be necessary.
Alternatively you could use the ::: notation, especially if you are not exporting that function, e.g.
mypackage:::my_function()

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' not found" error during package / vignette build

I'm using knitr to build an R package vignette. This process worked before R 3.0, but I haven't been able to rebuild the package under R 3.1.1.
When I try R CMD build I get an error message:
R CMD build Causata
* checking for file ‘Causata/DESCRIPTION’ ... OK
* preparing ‘Causata’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ...
ERROR Error in loadVignetteBuilder(vigns$pkgdir) :
vignette builder 'knitr' not found Calls: <Anonymous> -> loadVignetteBuilder
In addition:
Warning message: In tools::buildVignettes(dir = ".", tangle = TRUE) :
Files named as vignettes but with no recognized vignette engine:
‘vignettes/Causata-vignette.rnw’ (Is a VignetteBuilder field missing?)
Execution halted
My vignette file has a VignetteEngine call -- here are the first three lines:
% !Rnw weave = knitr
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Model training and export}
My package description file includes a VignetteBuilder field:
VignetteBuilder: knitr
I think I'm following the instructions for Rnw vignettes, so I'm baffled by the error message I'm seeing.
Incidentally, if I try to build the vignette directly then everything seems to work perfectly. This command generates the vignette PDF:
tools::buildVignettes(dir=".", tangle=TRUE)
My trouble seems to be only with R CMD build. Why won't the build work?
Here's my complete package DESCRIPTION file for reference:
Package: Causata
Type: Package
Title: Analysis utilities for binary classification and Causata users.
Version: 5.0-1
Date: 2014-10-09
Author: Justin Hemann, David Barker, Suzanne Weller, Jason McFall
Maintainer: Justin Hemann <justin.hemann#nice.com>
Description: The Causata package provides utilities for
extracting data from the Causata application, training regression / classification
models, and exporting models as PMML for scoring.
Depends: R (>= 2.15.1)
Imports: XML, R.utils, rjson, RCurl, stringr, yaml, boot, foreach, data.table, glmnet, ggplot2, methods
Suggests: knitr, doMC, testthat, pROC, RODBC, RMySQL
VignetteBuilder: knitr
License: GPL
LazyLoad: yes
URL: www.nice.com
According to the feedback of Josh O'Brien, I guess you might have the same issue as him. If you want to add some custom library paths, I'd recommend you to do it in ~/.Renviron using the environment variable R_LIBS_USER, instead of defining the library paths in ~/.Rprofile or Rprofile.site. The latter seems to be ignored by R CMD build and R CMD check.
Or you can add Sys.setenv(R_LIBS_USER="/my/r-package/dir/") to ~/.Rprofile.

Resources