knitr .Rmd vignettes do not appear with vignette()

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.

Tags:

R

Packages

Knitr