Skip to content

Commit 6453ecd

Browse files
committed
Require a usage field, use fs, other refactoring
1 parent ba0a221 commit 6453ecd

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

R/check-doc.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ man_message <- function(x) {
6565

6666
#' Check for missing documentation fields
6767
#'
68-
#' Checks all Rd files in `man/` for missing `\value` and `\examples` sections.
69-
#' These are flagged by CRAN on initial submission.
68+
#' Checks all Rd files in `man/` and looks for any that have a `\usage` section
69+
#' (i.e. a function) but that *don't* have `\value` and `\examples` sections.
70+
#' These missing fields are flagged by CRAN on initial submission.
7071
#'
7172
#' @template devtools
7273
#' @param fields A character vector of Rd field names to check for.
73-
#' @return A named list of character vectors, one for each field, containing
74+
#' @returns A named list of character vectors, one for each field, containing
7475
#' the names of Rd files missing that field. Returned invisibly.
7576
#' @export
7677
#' @examples
@@ -79,18 +80,23 @@ man_message <- function(x) {
7980
#' }
8081
check_doc_fields <- function(pkg = ".", fields = c("value", "examples")) {
8182
pkg <- as.package(pkg)
83+
fields <- stats::setNames(fields, fields)
8284

83-
paths <- dir(path(pkg$path, "man"), pattern = "\\.Rd$", full.names = TRUE)
85+
paths <- dir_ls(path(pkg$path, "man"), regexp = "\\.Rd$")
86+
names(paths) <- path_rel(paths, pkg$path)
8487
rd <- lapply(paths, tools::parse_Rd, permissive = TRUE)
88+
rd_tags <- lapply(rd, \(x) unlist(lapply(x, attr, "Rd_tag")))
8589

86-
has_tag <- function(x, tag) {
87-
tags <- unlist(lapply(x, attr, "Rd_tag"))
88-
any(tags %in% paste0("\\", tag))
90+
has_tag <- function(tags, this) {
91+
any(paste0("\\", this) %in% tags)
8992
}
9093

91-
results <- lapply(stats::setNames(fields, fields), function(field) {
92-
missing <- !vapply(rd, has_tag, logical(1), tag = field)
93-
path_rel(paths[missing], pkg$path)
94+
has_usage <- vapply(rd_tags, has_tag, logical(1), this = "usage")
95+
rd_tags <- rd_tags[has_usage]
96+
97+
results <- lapply(fields, function(field) {
98+
missing <- !vapply(rd_tags, has_tag, logical(1), this = field)
99+
names(rd_tags)[missing]
94100
})
95101

96102
for (field in fields) {

man/check_doc_fields.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-check-doc.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ test_that("check_doc_fields output - missing fields", {
33
dir.create(file.path(pkg, "man"))
44

55
writeLines(
6-
"\\name{foo}\\title{Foo}\\description{A function.}\\examples{foo()}",
6+
"\\name{foo}\\title{Foo}\\usage{foo()}\\description{A function.}\\examples{foo()}",
77
file.path(pkg, "man", "foo.Rd")
88
)
99
writeLines(
10-
"\\name{bar}\\title{Bar}\\description{A function.}\\value{Something.}",
10+
"\\name{bar}\\title{Bar}\\usage{foo()}\\description{A function.}\\value{Something.}",
1111
file.path(pkg, "man", "bar.Rd")
1212
)
1313

@@ -19,7 +19,7 @@ test_that("check_doc_fields output - all present", {
1919
dir.create(file.path(pkg, "man"))
2020

2121
writeLines(
22-
"\\name{foo}\\title{Foo}\\description{A function.}\\value{A value.}\\examples{foo()}",
22+
"\\name{foo}\\title{Foo}\\usage{foo()}\\description{A function.}\\value{A value.}\\examples{foo()}",
2323
file.path(pkg, "man", "foo.Rd")
2424
)
2525

0 commit comments

Comments
 (0)