knitr::opts_chunk$set (
    collapse = TRUE,
    warning = TRUE,
    message = TRUE,
    width = 120,
    comment = "#>",
    fig.retina = 2,
    fig.path = "README-"
)
options (repos = c (
    ropenscireviewtools = "https://ropensci-review-tools.r-universe.dev",
    CRAN = "https://cloud.r-project.org"
))
library (pkgcheck)
requireNamespace ("roxygen2")

The following checks are currently implemented in the pkgcheck package. Several of these are by default only shown when they fail; absence from a resultant checklist may be interpreted to indicate successful checks.

base_dir <- rprojroot::find_root (rprojroot::is_r_package)
flist <- list.files (file.path (base_dir, "R"), full.names = TRUE, pattern = "\\.R$")
blocks <- lapply (flist, function (i) roxygen2::parse_file (i, env = NULL))
blocks <- do.call (c, blocks) # flatten embedded lists

fn_names <- vapply (blocks, function (i) {
    pd <- utils::getParseData (parse (
        text = deparse (i$call),
        keep.source = TRUE,
        encoding = "UTF-8"
    ))
    if (!any (pd$token == "SYMBOL")) {
        return ("")
    } else {
        pd$text [which (pd$token == "SYMBOL") [1]]
    }},
character (1L),
USE.NAMES = FALSE
)

index <- grep ("^pkgchk\\_", fn_names)
blocks <- blocks [index]
fn_names <- fn_names [index]

block_docs <- lapply (seq_along (blocks), function (i) {
    list (
        fn_name = paste0 (i, ". ", fn_names [i]),
        title = roxygen2::block_get_tag (blocks [[i]], "title")$val,
        desc = roxygen2::block_get_tag (blocks [[i]], "description")$val,
        details = roxygen2::block_get_tag (blocks [[i]], "details")$val,
        notes = unlist (roxygen2::block_get_tags (blocks [[i]], "note"))
    )
})
# notes are not listed, only title, description, and detail fields.

block_str <- unlist (lapply (block_docs, function (i) {
    ret <- c (
        paste0 ("## *", i$fn_name, "*"),
        "",
        i$title,
        "",
        i$desc
    )

    if (!is.null (i$details)) {
        ret <- c (ret, "", i$details)
    }

    c (ret, "")
}))

cat (paste0 (block_str, collapse = "\n"))


ropensci-review-tools/pkgcheck documentation built on Nov. 24, 2024, 7:57 p.m.