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:

usethis::use_package("Rcpp", type = "Suggests")
## ℹ 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.105  0.006  0.134     10
## 2 FALSE       0 0.056  0.002  0.058      2
## 3 FALSE       0 0.172  0.018  1.440      1
## 4 FALSE       0 0.052  0.011  1.111     11
## 5 FALSE       0 0.005  0.001  0.006      3
## 6 FALSE       0 0.019  0.003  1.177      1
## 7 FALSE       0 0.339  0.027  7.827     12
## 8 FALSE       0 0.171  0.016  3.205      2
## 9 FALSE       0 0.129  0.027 26.935     12
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       result
## 1                                                                                                                                                                                                                                                                                                                                                   success, 10, 3, 10, 77, 3, 77, 10, 10, 45, 47, add_text_to_file() works, success, 16, 3, 16, 48, 3, 48, 16, 16, 45, 47, add_text_to_file() works, success, 17, 3, 17, 52, 3, 52, 17, 17, 45, 47, add_text_to_file() works, success, 22, 3, 22, 64, 3, 64, 22, 22, 45, 47, add_text_to_file() works, success, 25, 3, 25, 62, 3, 62, 25, 25, 45, 47, add_text_to_file() works, success, 26, 3, 26, 63, 3, 63, 26, 26, 45, 47, add_text_to_file() works, success, 27, 3, 27, 62, 3, 62, 27, 27, 45, 47, add_text_to_file() works, success, 32, 3, 32, 74, 3, 74, 32, 32, 45, 47, add_text_to_file() works, success, 37, 3, 38, 43, 3, 43, 37, 38, 45, 47, add_text_to_file() works, success, 43, 3, 44, 43, 3, 43, 43, 44, 45, 47, add_text_to_file() works
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     success, 50, 3, 53, 3, 3, 3, 50, 53, 45, 47, get_package_directory() works, success, 54, 3, 57, 3, 3, 3, 54, 57, 45, 47, get_package_directory() works
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            success, 70, 3, 70, 60, 3, 60, 70, 70, 45, 47, load_all() works
## 4                                                                                                                                                                                                                                                                                      success, 88, 3, 88, 53, 3, 53, 88, 88, 45, 47, check_unedited works, success, 93, 3, 93, 54, 3, 54, 93, 93, 45, 47, check_unedited works, success, 97, 3, 97, 53, 3, 53, 97, 97, 45, 47, check_unedited works, success, 102, 3, 102, 54, 3, 54, 102, 102, 45, 47, check_unedited works, success, 105, 3, 105, 53, 3, 53, 105, 105, 45, 47, check_unedited works, success, 112, 3, 112, 54, 3, 54, 112, 112, 45, 47, check_unedited works, success, 115, 3, 115, 53, 3, 53, 115, 115, 45, 47, check_unedited works, success, 123, 3, 123, 54, 3, 54, 123, 123, 45, 47, check_unedited works, success, 126, 3, 126, 53, 3, 53, 126, 126, 45, 47, check_unedited works, success, 134, 3, 134, 54, 3, 54, 134, 134, 45, 47, check_unedited works, success, 137, 3, 137, 53, 3, 53, 137, 137, 45, 47, check_unedited works
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     success, 150, 3, 153, 3, 3, 3, 150, 153, 45, 47, get_params_used works, success, 156, 3, 159, 3, 3, 3, 156, 159, 45, 47, get_params_used works, success, 163, 3, 168, 3, 3, 3, 163, 168, 45, 47, get_params_used works
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             success, 179, 3, 179, 78, 3, 78, 179, 179, 45, 47, Knuth-style references work
## 7 success, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, success, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, success, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, success, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, success, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, success, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, success, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, success, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, success, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, success, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works, success, 204, 5, 204, 72, 5, 72, 204, 204, 45, 48, Rendering in all possible ways works, success, 206, 5, 207, 70, 5, 70, 206, 207, 45, 48, Rendering in all possible ways works
## 8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       success, 291, 3, 292, 68, 3, 68, 291, 292, 45, 47, Rendering with minimal_eval=TRUE works, success, 299, 3, 300, 68, 3, 68, 299, 300, 45, 47, Rendering with minimal_eval=TRUE works
## 9                                                                                                                                                                                         success, 316, 3, 316, 78, 3, 78, 316, 316, 45, 47, templates can be knit, success, 317, 3, 317, 66, 3, 66, 317, 317, 45, 47, templates can be knit, success, 325, 3, 325, 80, 3, 80, 325, 325, 45, 47, templates can be knit, success, 326, 3, 326, 68, 3, 68, 326, 326, 45, 47, templates can be knit, success, 334, 3, 334, 80, 3, 80, 334, 334, 45, 47, templates can be knit, success, 335, 3, 335, 68, 3, 68, 335, 335, 45, 47, templates can be knit, success, 343, 3, 343, 84, 3, 84, 343, 343, 45, 47, templates can be knit, success, 344, 3, 344, 73, 3, 73, 344, 344, 45, 47, templates can be knit, success, 352, 3, 352, 83, 3, 83, 352, 352, 45, 47, templates can be knit, success, 353, 3, 353, 71, 3, 71, 353, 353, 45, 47, templates can be knit, success, 365, 3, 367, 5, 3, 5, 365, 367, 45, 47, templates can be knit, success, 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.

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 = "."))
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()
}
## [1] "litr"