R/prepare_book.R
prepare_book.Rd
Prepare customised bookdown from skeleton and template This function creates an Rstudio project in path, sets build type to "website", copies the content of book_skeleton at the root of the project, copies all files from the book template, modifies pre-defined variable book_title, author_name, creation_date, as well as any variable added by the user in replacements (index_title, index_content...), and inserts the content of index.txt in index.Rmd (here containing the user defined variables index_title and index_content).
prepare_book( path, replacements = c(book_title = "My book", author_name = "Marion Louveaux", creation_date = "`r Sys.Date()`", short_description = "An example of book with {bookprep}.", index_title = "Context"), skeleton = system.file("book_skeleton", package = "bookprep"), template = system.file("book_template_example", package = "bookprep"), pattern = "[.]Rmd$|[.]yml$|[.]md$" )
path | where to create the bookdown |
---|---|
replacements | a vector of correspondences between an input and an output. Input is fixed and corresponds to: book_title, author_name, creation_date, short_description and index_title |
skeleton | path to directory containing bookdown skeleton |
template | path to directory containing template files for chapters and index content |
pattern | regex to identify files to prepare (by default, all Rmd, yml and md files) |
used for side effect: file creation in path
# 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" ) )#>#>#>#>#>#>#> [1] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmp2M91OU/proj-66c24486913/_bookdown.yml" #> [2] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmp2M91OU/proj-66c24486913/_output.yml" #> [3] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmp2M91OU/proj-66c24486913/01-exploration.Rmd" #> [4] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmp2M91OU/proj-66c24486913/02-results.Rmd" #> [5] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmp2M91OU/proj-66c24486913/index.Rmd" #> [6] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmp2M91OU/proj-66c24486913/README.md"