The r CRANpkg("bookdown")
package can be used to build gitbook books
from multiple R markdown documents. The process for doing so is
well-documented for a single user with a directory of R markdown
documents.
A more complicated use case includes some additional requirements.
system.file()
to
access assets such as images, bibliography, etc. to enable compiling
the vignette after installation.inst
that will include
details of which vignette to include..Rmd
files
in one location, so need to ensure that chapters are "namespaced"
somehow. library(CollaborativeBookdown)
The first concern when building a collaborative bookdown book based on
workshop packages is to test which of the packages actually
installs. The testPackageInstalls()
function takes a character
vector of [repository strings] PUT IN REMOTES HERE. The
convenience function repoFromURLs()
can convert from plain URLs to
the format needed for installation.
z1 = testPackageInstalls(repos) head(z1)
Once testing for individual package installations has completed, a second step is to test and install the package including vignette build and installation. The output will again be a three-column data.frame with details of the install process.
Calling the testPackageInstalls()
function again, but with additional
parameters will install each package, build vignettes, and install those
as well.
z2 = testPackageInstalls(repos, build=TRUE, build_opts="", force=TRUE)
Since the r Githubpkg('seandavi/CollaborativeBookdown')
package needs
to have access to the R markdown source which should have been installed
with the package, a convenience function returns a data frame of packages,
absolute paths to each vignette, and the vignette filename (for easy linking
if that is desirable).
ivignettes = installedVignettes(c('BiocManager','GEOquery', 'dplyr', 'abc')) ivignettes
Create a fake vignette as text and write to file for testing and demonstrating functionality.
temp = tempfile() rmdtest = paste("# A test of multiple headers", "", "# second header", "", "And some text", sep="\n") writeLines(rmdtest, temp)
Bookdown has some special requirements for R markdown files that are going to appear as chapters in a bookdown book.
The checkVignette()
function performs some basic checks to see if the
supplied .Rmd
files meet these criteria.
checkVignette(temp)
The test .Rmd
file has incorrectly used more than one first-level
header, the number of headers. The fixMultipleFirstLevelHeaders()
function implements a kludge to fix the file.
cat(paste(fixMultipleFirstLevelHeaders(temp),collapse="\n"))
The new text has demoted all the first-level headers--except the first
one--to second-level headers. If necessary, use writeLines
to write
out the results to a file.
devtools::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.