File: lifecycle.R

package info (click to toggle)
r-cran-usethis 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,228 kB
  • sloc: sh: 26; makefile: 17; cpp: 6; ansic: 3
file content (45 lines) | stat: -rw-r--r-- 1,429 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' Use lifecycle badges
#'
#' @description
#' This helper:
#'
#' * Adds lifecycle as a dependency.
#' * Imports [lifecycle::deprecated()] for use in function arguments.
#' * Copies the lifecycle badges into `man/figures`.
#' * Reminds you how to use the badge syntax.
#'
#' Learn more at <https://lifecycle.r-lib.org/articles/communicate.html>
#'
#' @seealso [use_lifecycle_badge()] to signal the
#'  [lifecycle stage](https://lifecycle.r-lib.org/articles/stages.html) of
#'  your package as whole
#' @export
use_lifecycle <- function() {
  check_is_package("use_lifecycle()")
  check_uses_roxygen("use_lifecycle()")
  if (!uses_roxygen_md()) {
    ui_abort("
      Turn on roxygen2 markdown support with {.run usethis::use_roxygen_md()},
      then try again.")
  }

  use_package("lifecycle")
  use_import_from("lifecycle", "deprecated")

  dest_dir <- proj_path("man", "figures")
  create_directory(dest_dir)

  templ_dir <- path_package("usethis", "templates")
  templ_files <- dir_ls(templ_dir, glob = "*/lifecycle-*.svg")

  purrr::walk(templ_files, file_copy, dest_dir, overwrite = TRUE)
  ui_bullets(c(
    "v" = "Copied SVG badges to {.path {pth(dest_dir)}}.",
    "_" = "Add badges in documentation topics by inserting a line like this:",
    " " = "#' `r lifecycle::badge('experimental')`",
    " " = "#' `r lifecycle::badge('superseded')`",
    " " = "#' `r lifecycle::badge('deprecated')`"
  ))

  invisible(TRUE)
}