find_and_replace: Find and replace all variables in one of the files of the...

Description Usage Arguments Value Examples

View source: R/find_and_replace.R

Description

Find and replace all variables in one of the files of the book skeleton

Usage

1
2
3
4
5
6
find_and_replace(
  file,
  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")
)

Arguments

file

path of a file from skeleton: _bookdown.yml, _output.yml, index.Rmd, README.md

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

Value

path of the modified file

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# copy to a temporary file to avoid overwriting the package
index_tmp <- tempfile(pattern = "index-")

file.copy(from = system.file("book_skeleton/index.Rmd", package = "bookprep"), to = index_tmp)

bookprep:::find_and_replace(
  file = index_tmp,
  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"
  )
)

marionlouveaux/bookprep documentation built on Dec. 21, 2021, 2:45 p.m.