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.
Related
I am currently writing a vignette for an R package (in a quite complicated workflow, since the vignette is primarily written in Org-mode and then translated in .Rnw... okay, I'm not taking the easy way). So the vignette is basically made from a .Rnw file when the package builds.
In this vignette, I would like to use syntax highlighting with the minted LaTeX package. But this package requires to use LaTeX with the argument shell-escape.
Thus, when I try to build my package with R CMD build, I get the following error:
* creating vignettes ... ERROR
--- re-building ‘vignette.Rnw’ using Sweave
Error: processing vignette 'vignette.Rnw' failed with diagnostics:
l'exécution de 'texi2dvi' sur 'vignette.tex' failed
LaTeX errors:
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
I have no idea how I could specify that R must use this flag when it tries to build the vignette with LaTeX.
Thanks for your help!
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().
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
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.
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.