@@ -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# ' }
8081check_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 ) {
0 commit comments