The function prepare_book()
requires a {bookdown} skeleton and a template. The {bookdown} skeleton contains only the following files: "_bookdown.yml“,”_output.yml“,”index.Rmd“,”preamble.tex“,”README.md“, and”style.css". These files condition the architecture (the skeleton) of the future book, i.e. how it will be printed/rendered, its css style, link to bibliography and information about author, title and creation date. By default, prepare_book()
uses the skeleton stored in /book_skeleton
in the {bookprep} package. You can use your own skeleton if you prefer.
The {bookdown} skeleton created for the {bookprep} package was created by cleaning info specific to the {bookdown} package and replacing them by generic variable names:
- Index.Rmd: create variable book_title, author_name, creation_date (default to Sys.Date()
), short_description, index_title and index_content
- _bookdown.yml: reuse book_title variable
- _output.yml: reuse book_title variable, add info that this book was published with {bookprep}
- README.md: reuse variable book_title and specifies that this book was published with {bookprep}
The template contains Rmd files corresponding to the named chapters, an index.md file containing the content of the future index and, if needed, an extra .css file and an extra .bib file. Named chapters and index.md can include variables. These variables can be replaced with custom content using the replacements
parameter of prepare_book()
.
An example of template is included in {bookprep} in /book_template_example
. You can also provide your own template, or create a minimal one using the function initialize_template()
.
# Create temporary directory for reproducible example
dir_tmp <- tempfile(pattern = "proj-")
dir.create(dir_tmp)
# browseURL(dir_tmp)
prepare_book(
path = dir_tmp,
template = system.file("book_template_example", package = "bookprep"),
replacements = c(
# replacements mandatory for the bookdown skeleton
"book_title" = "My book",
"author_name" = "Marion Louveaux",
"creation_date" = "`r Sys.Date()`",
"short_description" = "An example of book with {bookprep}.",
# replacement specific to my template that you can add if you want
"index_title" = "Context"
)
)
As stated above, the template contains named chapters (Rmd files), an index.md file containing the level 1 title and content of the future index and, if needed, an extra .css file and an extra .bib file. The function initialize_template()
helps creating the named chapters and adding (or not) a reference chapter. You can then complete this template manually by writing custom variables in the chapter files (these will be replaced by prepare_book()
) and adding .css and .bib files to the template folder.
# Create temporary directory for reproducible example
dir_tmp <- tempfile(pattern = "proj-")
dir.create(dir_tmp)
# browseURL(dir_tmp)
initialize_template(
path = dir_tmp,
chapters = c(
"Introduction", "Material and Methods",
"Results", "Discussion"
),
references = NULL
)