Skip to content

Commit f7f8662

Browse files
committed
feat: add pkg_doc_obj/fun::grepl_arg_list
1 parent e04c013 commit f7f8662

4 files changed

Lines changed: 91 additions & 8 deletions

File tree

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<!-- generated by R package codedoc; do not modify! -->
22

3+
## News for version 0.10.2
4+
5+
### codedoc::pkg_doc_fun
6+
7+
`codedoc::pkg_doc_fun` gains new arg `grepl_arg_list`.
8+
9+
### codedoc::pkg_doc_obj
10+
11+
`codedoc::pkg_doc_obj` gains new arg `grepl_arg_list`.
12+
13+
314
## News for version 0.10.1
415

516
### codedoc::pkg_doc_obj

R/pkg_doc.R

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,31 @@ pkg_doc_codedoc_df__ <- function(
109109
pkg_doc_obj <- function(
110110
regex,
111111
rdname = NULL,
112-
text_file_paths = NULL
112+
text_file_paths = NULL,
113+
grepl_arg_list = NULL
113114
) {
114115
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-06-18", "0.10.0")
115116
# New function `codedoc::pkg_doc_obj`.
116117
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-06-18", "0.10.0")
118+
119+
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-03", "0.10.2")
120+
# `codedoc::pkg_doc_obj` gains new arg `grepl_arg_list`.
121+
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-03", "0.10.2")
122+
#' @param grepl_arg_list `[NULL, list]` (default `NULL`)
123+
#'
124+
#' Additional arguments to pass to `grepl` when detecting which comment
125+
#' blocks to include based on `key`.
126+
#' Arguments `pattern`, `x`, and `perl = TRUE` cannot be changed.
127+
#'
128+
#' - `NULL`: No additional arguments.
129+
#' - `list`: Pass these.
130+
dbc::assert_is_one_of(
131+
grepl_arg_list,
132+
funs = list(dbc::report_is_NULL,
133+
dbc::report_is_list)
134+
)
135+
grepl_arg_list <- as.list(grepl_arg_list)
136+
117137
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-02", "0.10.1")
118138
# Expand `codedoc::pkg_doc_obj` allowed `regex` patterns.
119139
# Now `regex` can be any string that `grepl(perl = TRUE)` can handle.
@@ -132,8 +152,11 @@ pkg_doc_obj <- function(
132152
#' use `roxygen` blocks normally unless there is a special reason to do
133153
#' otherwise.
134154
dbc::assert_is_character_nonNA_atom(regex)
155+
grepl_arg_list[["pattern"]] <- regex
156+
grepl_arg_list[["x"]] <- "test"
157+
grepl_arg_list[["perl"]] <- TRUE
135158
regex_test <- suppressWarnings(tryCatch(
136-
grepl(regex, "a", perl = TRUE), error = function(e) e
159+
do.call(grepl, grepl_arg_list), error = function(e) e
137160
))
138161
if (inherits(regex_test, "error")) {
139162
stop("Invalid `regex`: ", regex_test[["message"]])
@@ -203,9 +226,10 @@ pkg_doc_obj <- function(
203226
"descr" = paste0("^", regex, "$"),
204227
"return" = paste0("^return[(]", regex, "[)]$")
205228
)
229+
grepl_arg_list[["x"]] <- df[["key"]]
206230
lines_by_section <- lapply(names(regexes), function(nm) {
207-
regex <- regexes[nm]
208-
lines <- df[["comment_block"]][grepl(regex, df[["key"]], perl = TRUE)]
231+
grepl_arg_list[["pattern"]] <- regexes[nm]
232+
lines <- df[["comment_block"]][do.call(grepl, grepl_arg_list)]
209233
if (length(lines) > 0) {
210234
head <- switch(
211235
nm,
@@ -282,7 +306,8 @@ pkg_doc_obj <- function(
282306
pkg_doc_fun <- function(
283307
regex,
284308
rdname = NULL,
285-
text_file_paths = NULL
309+
text_file_paths = NULL,
310+
grepl_arg_list = NULL
286311
) {
287312
# @codedoc_comment_block codedoc::pkg_doc_obj
288313
# Document a function in an R package. Wrapper for
@@ -297,10 +322,14 @@ pkg_doc_fun <- function(
297322
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-06-18", "0.10.0")
298323
# `codedoc::pkg_doc_fun` now a wrapper for `codedoc::pkg_doc_obj`.
299324
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-06-18", "0.10.0")
325+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-07-03", "0.10.2")
326+
# `codedoc::pkg_doc_fun` gains new arg `grepl_arg_list`.
327+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-07-03", "0.10.2")
300328
return(codedoc::pkg_doc_obj(
301329
regex = regex,
302330
rdname = rdname,
303-
text_file_paths = text_file_paths
331+
text_file_paths = text_file_paths,
332+
grepl_arg_list = grepl_arg_list
304333
))
305334
}
306335

man/codedoc-package.Rd

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

man/pkg_doc.Rd

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

0 commit comments

Comments
 (0)