11 Documenting the package and testing

We finish by running commands that will document and test litr.

The formatting of the test output does not print out very neatly.

We download the latest release:

litr::document()
install_old <- function() {
  remotes::install_github("jacobbien/litr-project@*release", subdir = "litr")
}
xfun::Rscript_call(test_litr,
                   list(install_old = install_old, location_of_new = "."))
## ℹ Updating litr documentation
## ℹ Loading litr
## Writing 'NAMESPACE'
## Writing 'create_from_template.Rd'
## Writing 'draft.Rd'
## Writing 'draft_data.Rd'
## Writing 'draft_rcpp.Rd'
## Writing 'draft_extras.Rd'
## Writing 'draft_armadillo.Rd'
## Writing 'draft_bookdown.Rd'
## Writing 'add_readme.Rd'
## Writing 'add_hex_sticker.Rd'
## Writing 'add_vignettes.Rd'
## Writing 'add_pkgdown.Rd'
## Writing 'hash_package_directory.Rd'
## Writing 'description_litr_hash_field_name.Rd'
## Writing 'write_hash_to_description.Rd'
## Writing 'read_hash_from_description.Rd'
## Writing 'check_unedited.Rd'
## Writing 'litr-package.Rd'
## Writing 'do_not_edit_message.Rd'
## Writing 'document.Rd'
## Writing 'litrify_output_format.Rd'
## Writing 'description_litr_version_field_name.Rd'
## Writing 'write_version_to_description.Rd'
## Writing 'get_package_directory.Rd'
## Writing 'litr_pdf_document.Rd'
## Writing 'litr_html_document.Rd'
## Writing 'add_function_hyperlinks.Rd'
## Writing 'insert_hrefs.Rd'
## Writing 'add_chunk_label_hyperlinks.Rd'
## Writing 'replace_ansi_sequences.Rd'
## Writing 'litr_gitbook.Rd'
## Writing 'render.Rd'
## Writing 'with_cleanup.Rd'
## Writing 'restore_knitr_objects.Rd'
## Writing 'remove_rstudio_extras.Rd'
## Writing 'get_params_used.Rd'
## Writing 'load_all.Rd'
## Writing 'send_to_package.Rd'
## Writing 'add_text_to_file.Rd'
## Writing 'setup.Rd'
## Writing 'find_labels.Rd'
## Writing 'make_noticeable.Rd'
## Writing 'test_litr.Rd'
##      file context                                   test nb failed skipped
## 1 tests.R   tests               add_text_to_file() works 10      0   FALSE
## 2 tests.R   tests          get_package_directory() works  2      0   FALSE
## 3 tests.R   tests                       load_all() works  1      0   FALSE
## 4 tests.R   tests                   check_unedited works 11      0   FALSE
## 5 tests.R   tests                  get_params_used works  3      0   FALSE
## 6 tests.R   tests            Knuth-style references work  1      0   FALSE
## 7 tests.R   tests   Rendering in all possible ways works 12      0   FALSE
## 8 tests.R   tests Rendering with minimal_eval=TRUE works  2      0   FALSE
## 9 tests.R   tests                  templates can be knit 12      0   FALSE
##   error warning  user system   real passed
## 1 FALSE       0 0.080  0.007  0.086     10
## 2 FALSE       0 0.003  0.001  0.003      2
## 3 FALSE       0 0.193  0.018  1.137      1
## 4 FALSE       0 0.047  0.010  1.097     11
## 5 FALSE       0 0.004  0.002  0.006      3
## 6 FALSE       0 0.017  0.002  1.113      1
## 7 FALSE       0 0.346  0.026  7.558     12
## 8 FALSE       0 0.209  0.014  3.106      2
## 9 FALSE       0 0.114  0.033 49.803     12
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   result
## 1 , 10, 3, 10, 77, 3, 77, 10, 10, testthat::expect_error(add_text_to_file(sometxt, myfile, req_exist = TRUE)), expect_condition_matching("error", {,     {,         object,     }, }, regexp = regexp, class = class, ..., inherit = inherit, info = info, ,     label = label), quasi_capture(enquo(object), label, capture_matching_condition, ,     matches = matcher), .capture(act$val <- eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), ,     ...), withCallingHandlers(expr, condition = function(cnd) {,     if (!is.null(matched) || !matches(cnd)) {,         return(),     },     if (can_entrace(cnd)) {,         cnd <- cnd_entrace(cnd),     },     matched <<- cnd,     if (inherits(cnd, "message") || inherits(cnd, "warning")) {,         cnd_muffle(cnd),     },     else if (inherits(cnd, "error") || inherits(cnd, "skip")) {,         return_from(tl, cnd),     }, }), eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), add_text_to_file(sometxt, myfile, req_exist = TRUE), 0, 1, 2, 3, 4, 3, 0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, testthat, testthat, testthat, testthat, base, rlang, litr, ::, :::, :::, local, ::, ::, :::, 45, 47, add_text_to_file() works, fs::file_exists(myfile) is not TRUE\n\n, 16, 3, 16, 48, 3, 48, 16, 16, 45, 47, add_text_to_file() works, `sometxt` (`actual`) not equal to readLines(myfile) (`expected`).\n\n, 17, 3, 17, 52, 3, 52, 17, 17, 45, 47, add_text_to_file() works, c(sometxt, moretxt) (`actual`) not equal to readLines(myfile) (`expected`).\n\n, 22, 3, 22, 64, 3, 64, 22, 22, 45, 47, add_text_to_file() works, , 25, 3, 25, 62, 3, 62, 25, 25, testthat::expect_error(add_text_to_file(sometxt, myfile, 0)), expect_condition_matching("error", {,     {,         object,     }, }, regexp = regexp, class = class, ..., inherit = inherit, info = info, ,     label = label), quasi_capture(enquo(object), label, capture_matching_condition, ,     matches = matcher), .capture(act$val <- eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), ,     ...), withCallingHandlers(expr, condition = function(cnd) {,     if (!is.null(matched) || !matches(cnd)) {,         return(),     },     if (can_entrace(cnd)) {,         cnd <- cnd_entrace(cnd),     },     matched <<- cnd,     if (inherits(cnd, "message") || inherits(cnd, "warning")) {,         cnd_muffle(cnd),     },     else if (inherits(cnd, "error") || inherits(cnd, "skip")) {,         return_from(tl, cnd),     }, }), eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), add_text_to_file(sometxt, myfile, 0), 0, 1, 2, 3, 4, 3, 0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, testthat, testthat, testthat, testthat, base, rlang, litr, ::, :::, :::, local, ::, ::, :::, 45, 47, add_text_to_file() works, , 26, 3, 26, 63, 3, 63, 26, 26, testthat::expect_error(add_text_to_file(sometxt, myfile, -1)), expect_condition_matching("error", {,     {,         object,     }, }, regexp = regexp, class = class, ..., inherit = inherit, info = info, ,     label = label), quasi_capture(enquo(object), label, capture_matching_condition, ,     matches = matcher), .capture(act$val <- eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), ,     ...), withCallingHandlers(expr, condition = function(cnd) {,     if (!is.null(matched) || !matches(cnd)) {,         return(),     },     if (can_entrace(cnd)) {,         cnd <- cnd_entrace(cnd),     },     matched <<- cnd,     if (inherits(cnd, "message") || inherits(cnd, "warning")) {,         cnd_muffle(cnd),     },     else if (inherits(cnd, "error") || inherits(cnd, "skip")) {,         return_from(tl, cnd),     }, }), eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), add_text_to_file(sometxt, myfile, -1), 0, 1, 2, 3, 4, 3, 0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, testthat, testthat, testthat, testthat, base, rlang, litr, ::, :::, :::, local, ::, ::, :::, 45, 47, add_text_to_file() works, , 27, 3, 27, 62, 3, 62, 27, 27, testthat::expect_error(add_text_to_file(sometxt, myfile, 5)), expect_condition_matching("error", {,     {,         object,     }, }, regexp = regexp, class = class, ..., inherit = inherit, info = info, ,     label = label), quasi_capture(enquo(object), label, capture_matching_condition, ,     matches = matcher), .capture(act$val <- eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), ,     ...), withCallingHandlers(expr, condition = function(cnd) {,     if (!is.null(matched) || !matches(cnd)) {,         return(),     },     if (can_entrace(cnd)) {,         cnd <- cnd_entrace(cnd),     },     matched <<- cnd,     if (inherits(cnd, "message") || inherits(cnd, "warning")) {,         cnd_muffle(cnd),     },     else if (inherits(cnd, "error") || inherits(cnd, "skip")) {,         return_from(tl, cnd),     }, }), eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), add_text_to_file(sometxt, myfile, 5), 0, 1, 2, 3, 4, 3, 0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, testthat, testthat, testthat, testthat, base, rlang, litr, ::, :::, :::, local, ::, ::, :::, 45, 47, add_text_to_file() works, c(moretxt2, sometxt, moretxt) (`actual`) not equal to readLines(myfile) (`expected`).\n\n, 32, 3, 32, 74, 3, 74, 32, 32, 45, 47, add_text_to_file() works, c(moretxt2, moretxt3, sometxt, moretxt) (`actual`) not equal to readLines(myfile) (`expected`).\n\n, 37, 3, 38, 43, 3, 43, 37, 38, 45, 47, add_text_to_file() works, c(moretxt2, moretxt3, sometxt, moretxt, moretxt4) (`actual`) not equal to readLines(myfile) (`expected`).\n\n, 43, 3, 44, 43, 3, 43, 43, 44, 45, 47, add_text_to_file() works
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  get_package_directory(".", "mypkg", input) (`actual`) not equal to file.path("inputdir", "mypkg") (`expected`).\n\n, 50, 3, 53, 3, 3, 3, 50, 53, 45, 47, get_package_directory() works, get_package_directory("..", "mypkg", input) (`actual`) not equal to file.path("inputdir", "..", "mypkg") (`expected`).\n\n, 54, 3, 57, 3, 3, 3, 54, 57, 45, 47, get_package_directory() works
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    say_hello("Jacob") (`actual`) not equal to "Hello Jacob!" (`expected`).\n\n, 70, 3, 70, 60, 3, 60, 70, 70, 45, 47, load_all() works
## 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      check_unedited(package_path) is not TRUE\n\n, 88, 3, 88, 53, 3, 53, 88, 88, 45, 47, check_unedited works, check_unedited(package_path) is not FALSE\n\n, 93, 3, 93, 54, 3, 54, 93, 93, 45, 47, check_unedited works, check_unedited(package_path) is not TRUE\n\n, 97, 3, 97, 53, 3, 53, 97, 97, 45, 47, check_unedited works, check_unedited(package_path) is not FALSE\n\n, 102, 3, 102, 54, 3, 54, 102, 102, 45, 47, check_unedited works, check_unedited(package_path) is not TRUE\n\n, 105, 3, 105, 53, 3, 53, 105, 105, 45, 47, check_unedited works, check_unedited(package_path) is not FALSE\n\n, 112, 3, 112, 54, 3, 54, 112, 112, 45, 47, check_unedited works, check_unedited(package_path) is not TRUE\n\n, 115, 3, 115, 53, 3, 53, 115, 115, 45, 47, check_unedited works, check_unedited(package_path) is not FALSE\n\n, 123, 3, 123, 54, 3, 54, 123, 123, 45, 47, check_unedited works, check_unedited(package_path) is not TRUE\n\n, 126, 3, 126, 53, 3, 53, 126, 126, 45, 47, check_unedited works, check_unedited(package_path) is not FALSE\n\n, 134, 3, 134, 54, 3, 54, 134, 134, 45, 47, check_unedited works, check_unedited(package_path) is not TRUE\n\n, 137, 3, 137, 53, 3, 53, 137, 137, 45, 47, check_unedited works
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       `default_params` (`actual`) not equal to rmarkdown::yaml_front_matter(rmd_file)$params (`expected`).\n\n, 150, 3, 153, 3, 3, 3, 150, 153, 45, 47, get_params_used works, get_params_used(rmd_file, passed_params = list(package_parent_dir = "dir")) (`actual`) not equal to `params1` (`expected`).\n\n, 156, 3, 159, 3, 3, 3, 156, 159, 45, 47, get_params_used works, get_params_used(...) (`actual`) not equal to `params2` (`expected`).\n\n, 163, 3, 168, 3, 3, 3, 163, 168, 45, 47, get_params_used works
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           fs::file_exists(file.path(dir, "create-rknuth.html")) is not TRUE\n\n, 179, 3, 179, 78, 3, 78, 179, 179, 45, 47, Knuth-style references work
## 7                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     readLines(html_file_a) (`actual`) not equal to readLines(html_file) (`expected`).\n\n, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, readLines(html_file_a) (`actual`) not equal to readLines(html_file) (`expected`).\n\n, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, readLines(html_file_a) (`actual`) not equal to readLines(html_file) (`expected`).\n\n, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, readLines(html_file_a) (`actual`) not equal to readLines(html_file) (`expected`).\n\n, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, readLines(html_file_a) (`actual`) not equal to readLines(html_file) (`expected`).\n\n, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, readLines(html_file_a) (`actual`) not equal to readLines(html_file) (`expected`).\n\n, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works
## 8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 291, 3, 292, 68, 3, 68, 291, 292, 45, 47, Rendering with minimal_eval=TRUE works, readLines(file.path(pkg, "DESCRIPTION")) (`actual`) not equal to readLines(file.path(pkg_a, "DESCRIPTION")) (`expected`).\n\n, 299, 3, 300, 68, 3, 68, 299, 300, 45, 47, Rendering with minimal_eval=TRUE works
## 9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          fs::file_exists(file.path(dir, "create-rhello.html")) is not TRUE\n\n, 316, 3, 316, 78, 3, 78, 316, 316, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "rhello")) is not TRUE\n\n, 317, 3, 317, 66, 3, 66, 317, 317, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "create-rhasdata.html")) is not TRUE\n\n, 325, 3, 325, 80, 3, 80, 325, 325, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "rhasdata")) is not TRUE\n\n, 326, 3, 326, 68, 3, 68, 326, 326, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "create-withrcpp.html")) is not TRUE\n\n, 334, 3, 334, 80, 3, 80, 334, 334, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "withrcpp")) is not TRUE\n\n, 335, 3, 335, 68, 3, 68, 335, 335, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "create-witharmadillo.Rmd")) is not TRUE\n\n, 343, 3, 343, 84, 3, 84, 343, 343, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "witharmadillo")) is not TRUE\n\n, 344, 3, 344, 73, 3, 73, 344, 344, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "create-withpkgdown.html")) is not TRUE\n\n, 352, 3, 352, 83, 3, 83, 352, 352, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "withpkgdown")) is not TRUE\n\n, 353, 3, 353, 71, 3, 71, 353, 353, 45, 47, templates can be knit, fs::file_exists(...) is not TRUE\n\n, 365, 3, 367, 5, 3, 5, 365, 367, 45, 47, templates can be knit, fs::file_exists(file.path(dir, "create-frombookdown", "frombookdown")) is not TRUE\n\n, 368, 3, 370, 5, 3, 5, 368, 370, 45, 47, templates can be knit

11.1 Add examples folder with the output of knitting each example

In this section, we will litr-knit each template and put the outputs in an examples directory that lives outside of the litr R package. These examples are linked to in README.Rmd.

build_all_templates <- function(install_old, location_of_new) {
  devtools::install(location_of_new)

  example_dir <- file.path("..", "examples")
  if (fs::dir_exists(example_dir)) fs::dir_delete(example_dir)
  fs::dir_create(example_dir)
  
  templates <- fs::path_file(fs::dir_ls("inst/rmarkdown/templates"))
  templates_bookdown <- stringr::str_subset(templates, "bookdown")
  templates_nonbookdown <- setdiff(templates, templates_bookdown)
  for (template in templates_nonbookdown) {
    tmp_file <- file.path(example_dir, "temp.Rmd")
    rmarkdown::draft(tmp_file, template, package = "litr", edit = FALSE)
    pkg_name <- rmarkdown::yaml_front_matter(tmp_file)$params$package_name
    rmd_file <- file.path(example_dir, paste0("create-", pkg_name, ".Rmd"))
    fs::file_move(tmp_file, rmd_file)
    render(rmd_file)
    # move to a template-specific directory:
    template_dir <- file.path(example_dir, template)
    fs::dir_create(template_dir)
    fs::file_move(fs::dir_ls(example_dir, regexp = pkg_name), template_dir)
    # move the source-files directory
    if (fs::dir_exists(file.path(example_dir, "source-files"))) {
      fs::dir_create(file.path(example_dir, template, "source-files"))
      fs::dir_copy(file.path(example_dir, "source-files"),
                   file.path(example_dir, template))
      fs::dir_delete(file.path(example_dir, "source-files"))
    }
    # move the docs directory (when pkgdown creates one)
    if (fs::dir_exists(file.path(example_dir, "docs"))) {
      fs::dir_create(file.path(example_dir, template, "docs"))
      fs::dir_copy(file.path(example_dir, "docs"),
                   file.path(example_dir, template))
      fs::dir_delete(file.path(example_dir, "docs"))
    }
  }

  for (template in templates_bookdown) {
    tmp_dir <- file.path(example_dir, "temp")
    rmarkdown::draft(file.path(example_dir, "temp.Rmd"),
                     template,
                     package = "litr",
                     edit = FALSE)
    prev_dir <- getwd()
    setwd(tmp_dir)
    fs::file_delete("temp.Rmd")
    render("index.Rmd")
    # move to a template-specific directory:
    setwd(prev_dir)
    fs::dir_copy(tmp_dir, file.path(example_dir, template))
    fs::dir_delete(tmp_dir)
  }

  install_old()
}
xfun::Rscript_call(build_all_templates,
                   list(install_old = install_old, location_of_new = "."))
## [1] "litr"